Browse Source

adding test and updating condition

Bay Dodd 11 years ago
parent
commit
19f0a91c4e
2 changed files with 14 additions and 2 deletions
  1. +9
    -0
      mux_test.go
  2. +5
    -2
      regexp.go

+ 9
- 0
mux_test.go View File

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


+ 5
- 2
regexp.go View File

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


Loading…
Cancel
Save