adding test and updating condition
This commit is contained in:
@@ -597,6 +597,15 @@ func TestQueries(t *testing.T) {
|
|||||||
path: "",
|
path: "",
|
||||||
shouldMatch: true,
|
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 {
|
for _, test := range tests {
|
||||||
|
|||||||
@@ -89,8 +89,11 @@ func newRouteRegexp(tpl string, matchHost, matchPrefix, matchQuery, strictSlash
|
|||||||
if strictSlash {
|
if strictSlash {
|
||||||
pattern.WriteString("[/]?")
|
pattern.WriteString("[/]?")
|
||||||
}
|
}
|
||||||
if matchQuery && len(idxs) == 0 {
|
if matchQuery {
|
||||||
pattern.WriteString(defaultPattern)
|
// Add the default pattern if the query value is empty
|
||||||
|
if queryVal := strings.SplitN(template, "=", 2)[1]; queryVal == "" {
|
||||||
|
pattern.WriteString(defaultPattern)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !matchPrefix {
|
if !matchPrefix {
|
||||||
pattern.WriteByte('$')
|
pattern.WriteByte('$')
|
||||||
|
|||||||
Reference in New Issue
Block a user