Browse Source

updating query match string

Bay Dodd 11 years ago
parent
commit
fe40f0d056
2 changed files with 16 additions and 3 deletions
  1. +9
    -0
      mux_test.go
  2. +7
    -3
      regexp.go

+ 9
- 0
mux_test.go View File

@ -606,6 +606,15 @@ 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,
},
}
for _, test := range tests {


+ 7
- 3
regexp.go View File

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