Browse Source

Merge pull request #111 from burrbd/master

Issue #109
pull/112/head
Kamil Kisiel 11 years ago
parent
commit
61445102e8
  1. 36
      mux_test.go
  2. 10
      regexp.go

36
mux_test.go

@ -597,6 +597,24 @@ func TestQueries(t *testing.T) { @@ -597,6 +597,24 @@ func TestQueries(t *testing.T) {
path: "",
shouldMatch: true,
},
{
title: "Queries route with empty value and no parameter in request, should not match",
route: new(Route).Queries("foo", ""),
request: newRequest("GET", "http://localhost"),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: false,
},
{
title: "Queries route with empty value and empty parameter in request, should match",
route: new(Route).Queries("foo", ""),
request: newRequest("GET", "http://localhost?foo="),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: true,
},
{
title: "Queries route with overlapping value, should not match",
route: new(Route).Queries("foo", "bar"),
@ -606,6 +624,24 @@ func TestQueries(t *testing.T) { @@ -606,6 +624,24 @@ func TestQueries(t *testing.T) {
path: "",
shouldMatch: false,
},
{
title: "Queries route with no parameter in request, should not match",
route: new(Route).Queries("foo", "{bar}"),
request: newRequest("GET", "http://localhost"),
vars: map[string]string{},
host: "",
path: "",
shouldMatch: false,
},
{
title: "Queries route with empty parameter in request, should match",
route: new(Route).Queries("foo", "{bar}"),
request: newRequest("GET", "http://localhost?foo="),
vars: map[string]string{"foo": ""},
host: "",
path: "",
shouldMatch: true,
},
}
for _, test := range tests {

10
regexp.go

@ -186,9 +186,13 @@ func (r *routeRegexp) getUrlQuery(req *http.Request) string { @@ -186,9 +186,13 @@ func (r *routeRegexp) getUrlQuery(req *http.Request) string {
if !r.matchQuery {
return ""
}
key := strings.Split(r.template, "=")[0]
val := req.URL.Query().Get(key)
return key + "=" + val
templateKey := strings.Split(r.template, "=")[0]
for key, vals := range req.URL.Query() {
if key == templateKey && len(vals) > 0 {
return key + "=" + vals[0]
}
}
return ""
}
func (r *routeRegexp) matchQueryString(req *http.Request) bool {

Loading…
Cancel
Save