diff --git a/mux_test.go b/mux_test.go index 0f61da8..9bed205 100644 --- a/mux_test.go +++ b/mux_test.go @@ -597,6 +597,15 @@ func TestQueries(t *testing.T) { path: "", shouldMatch: true, }, + { + title: "Queries route with overlapping value, should not match", + route: new(Route).Queries("foo", "bar"), + request: newRequest("GET", "http://localhost?foo=barfoo"), + vars: map[string]string{}, + host: "", + path: "", + shouldMatch: false, + }, } for _, test := range tests { diff --git a/regexp.go b/regexp.go index 8ecf270..a1f6eb6 100644 --- a/regexp.go +++ b/regexp.go @@ -89,8 +89,11 @@ func newRouteRegexp(tpl string, matchHost, matchPrefix, matchQuery, strictSlash if strictSlash { pattern.WriteString("[/]?") } - if matchQuery && len(idxs) == 0 { - pattern.WriteString(defaultPattern) + if matchQuery { + // Add the default pattern if the query value is empty + if queryVal := strings.SplitN(template, "=", 2)[1]; queryVal == "" { + pattern.WriteString(defaultPattern) + } } if !matchPrefix { pattern.WriteByte('$')