diff options
| author | Mark Sargent <99003+sarge@users.noreply.github.com> | 2019-11-30 09:05:22 +1300 | 
|---|---|---|
| committer | Matt Holt <mholt@users.noreply.github.com> | 2019-11-29 13:05:22 -0700 | 
| commit | 8b7d6a9ee8b7f62142df3516a9d9b96031be33fd (patch) | |
| tree | 95796a3c617515b36453eb81855cb983f71070ac /modules/caddyhttp/matchers.go | |
| parent | 7c7ef8d40e3af35444d522debc95451c04666615 (diff) | |
v2: fixes query matcher parsing (#2901)
* fixes query matcher parsing
* return correct argument error when parsing query matcher
Diffstat (limited to 'modules/caddyhttp/matchers.go')
| -rw-r--r-- | modules/caddyhttp/matchers.go | 20 | 
1 files changed, 15 insertions, 5 deletions
| diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go index c0e3872..82fb04a 100644 --- a/modules/caddyhttp/matchers.go +++ b/modules/caddyhttp/matchers.go @@ -255,8 +255,16 @@ func (MatchQuery) CaddyModule() caddy.ModuleInfo {  // UnmarshalCaddyfile implements caddyfile.Unmarshaler.  func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { +	if *m == nil { +		*m = make(map[string][]string) +	} +  	for d.Next() { -		parts := strings.SplitN(d.Val(), "=", 2) +		var query string +		if !d.Args(&query) { +			return d.ArgErr() +		} +		parts := strings.SplitN(query, "=", 2)  		if len(parts) != 2 {  			return d.Errf("malformed query matcher token: %s; must be in param=val format", d.Val())  		} @@ -268,10 +276,12 @@ func (m *MatchQuery) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {  // Match returns true if r matches m.  func (m MatchQuery) Match(r *http.Request) bool {  	for param, vals := range m { -		paramVal := r.URL.Query().Get(param) -		for _, v := range vals { -			if paramVal == v { -				return true +		paramVal, found := r.URL.Query()[param] +		if found { +			for _, v := range vals { +				if paramVal[0] == v || v == "*" { +					return true +				}  			}  		}  	} | 
