updating query match string
This commit is contained in:
@@ -606,6 +606,15 @@ func TestQueries(t *testing.T) {
|
|||||||
path: "",
|
path: "",
|
||||||
shouldMatch: false,
|
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 {
|
for _, test := range tests {
|
||||||
|
|||||||
10
regexp.go
10
regexp.go
@@ -186,9 +186,13 @@ func (r *routeRegexp) getUrlQuery(req *http.Request) string {
|
|||||||
if !r.matchQuery {
|
if !r.matchQuery {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
key := strings.Split(r.template, "=")[0]
|
templateKey := strings.Split(r.template, "=")[0]
|
||||||
val := req.URL.Query().Get(key)
|
for key, vals := range req.URL.Query() {
|
||||||
return key + "=" + val
|
if key == templateKey && len(vals) > 0 {
|
||||||
|
return key + "=" + vals[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *routeRegexp) matchQueryString(req *http.Request) bool {
|
func (r *routeRegexp) matchQueryString(req *http.Request) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user