make the getPath method safer, fixing panics within App Engine (#189)
This commit is contained in:
committed by
Matt Silverlock
parent
674ef1c280
commit
34bf6dc9fa
8
mux.go
8
mux.go
@@ -369,12 +369,8 @@ func getPath(req *http.Request) string {
|
|||||||
// for < 1.5 server side workaround
|
// for < 1.5 server side workaround
|
||||||
// http://localhost/path/here?v=1 -> /path/here
|
// http://localhost/path/here?v=1 -> /path/here
|
||||||
path := req.RequestURI
|
path := req.RequestURI
|
||||||
if i := len(req.URL.Scheme); i > 0 {
|
path = strings.TrimPrefix(path, req.URL.Scheme+`://`)
|
||||||
path = path[i+len(`://`):]
|
path = strings.TrimPrefix(path, req.URL.Host)
|
||||||
}
|
|
||||||
if i := len(req.URL.Host); i > 0 {
|
|
||||||
path = path[i:]
|
|
||||||
}
|
|
||||||
if i := strings.LastIndex(path, "?"); i > -1 {
|
if i := strings.LastIndex(path, "?"); i > -1 {
|
||||||
path = path[:i]
|
path = path[:i]
|
||||||
}
|
}
|
||||||
|
|||||||
14
mux_test.go
14
mux_test.go
@@ -292,6 +292,20 @@ func TestPath(t *testing.T) {
|
|||||||
pathTemplate: `/`,
|
pathTemplate: `/`,
|
||||||
shouldMatch: true,
|
shouldMatch: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "Path route, match root with no host, App Engine format",
|
||||||
|
route: new(Route).Path("/"),
|
||||||
|
request: func() *http.Request {
|
||||||
|
r := newRequest("GET", "http://localhost/")
|
||||||
|
r.RequestURI = "/"
|
||||||
|
return r
|
||||||
|
}(),
|
||||||
|
vars: map[string]string{},
|
||||||
|
host: "",
|
||||||
|
path: "/",
|
||||||
|
pathTemplate: `/`,
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "Path route, wrong path in request in request URL",
|
title: "Path route, wrong path in request in request URL",
|
||||||
route: new(Route).Path("/111/222/333"),
|
route: new(Route).Path("/111/222/333"),
|
||||||
|
|||||||
Reference in New Issue
Block a user