Browse Source

make the getPath method safer, fixing panics within App Engine (#189)

pull/127/merge
Aaron Taylor 9 years ago committed by Matt Silverlock
parent
commit
34bf6dc9fa
  1. 8
      mux.go
  2. 14
      mux_test.go

8
mux.go

@ -369,12 +369,8 @@ func getPath(req *http.Request) string { @@ -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

@ -292,6 +292,20 @@ func TestPath(t *testing.T) { @@ -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"),

Loading…
Cancel
Save