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
|
||||
// http://localhost/path/here?v=1 -> /path/here
|
||||
path := req.RequestURI
|
||||
if i := len(req.URL.Scheme); i > 0 {
|
||||
path = path[i+len(`://`):]
|
||||
}
|
||||
if i := len(req.URL.Host); i > 0 {
|
||||
path = path[i:]
|
||||
}
|
||||
path = strings.TrimPrefix(path, req.URL.Scheme+`://`)
|
||||
path = strings.TrimPrefix(path, req.URL.Host)
|
||||
if i := strings.LastIndex(path, "?"); i > -1 {
|
||||
path = path[:i]
|
||||
}
|
||||
|
||||
14
mux_test.go
14
mux_test.go
@@ -292,6 +292,20 @@ func TestPath(t *testing.T) {
|
||||
pathTemplate: `/`,
|
||||
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",
|
||||
route: new(Route).Path("/111/222/333"),
|
||||
|
||||
Reference in New Issue
Block a user