Browse Source

adding test and updating condition

pull/108/head
Bay Dodd 11 years ago
parent
commit
19f0a91c4e
  1. 9
      mux_test.go
  2. 7
      regexp.go

9
mux_test.go

@ -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 {

7
regexp.go

@ -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('$')

Loading…
Cancel
Save