From 8b7d6a9ee8b7f62142df3516a9d9b96031be33fd Mon Sep 17 00:00:00 2001 From: Mark Sargent <99003+sarge@users.noreply.github.com> Date: Sat, 30 Nov 2019 09:05:22 +1300 Subject: v2: fixes query matcher parsing (#2901) * fixes query matcher parsing * return correct argument error when parsing query matcher --- modules/caddyhttp/matchers.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'modules/caddyhttp/matchers.go') 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 + } } } } -- cgit v1.2.3