Skip to content

Commit

Permalink
Add test and fix for escaped query values.
Browse files Browse the repository at this point in the history
Reproduces and fixes #238.
  • Loading branch information
ChrisHines authored and kisielk committed Jun 2, 2017
1 parent c7a138d commit 18fca31
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type routeTest struct {
scheme string // the expected scheme of the built URL
host string // the expected host of the built URL
path string // the expected path of the built URL
query string // the expected query string to match
query string // the expected query string of the built URL
pathTemplate string // the expected path template of the route
hostTemplate string // the expected host template of the route
methods []string // the expected route methods
Expand Down Expand Up @@ -974,6 +974,16 @@ func TestQueries(t *testing.T) {
path: "",
shouldMatch: false,
},
{
title: "Queries route with pattern, match, escaped value",
route: new(Route).Queries("foo", "{v1}"),
request: newRequest("GET", "http://localhost?foo=%25bar%26%20%2F%3D%3F"),
vars: map[string]string{"v1": "%bar& /=?"},
host: "",
path: "",
query: "foo=%25bar%26+%2F%3D%3F",
shouldMatch: true,
},
}

for _, test := range tests {
Expand Down
2 changes: 1 addition & 1 deletion regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func newRouteRegexp(tpl string, matchHost, matchPrefix, matchQuery, strictSlash,
// Now let's parse it.
defaultPattern := "[^/]+"
if matchQuery {
defaultPattern = "[^?&]*"
defaultPattern = ".*"
} else if matchHost {
defaultPattern = "[^.]+"
matchPrefix = false
Expand Down

0 comments on commit 18fca31

Please sign in to comment.