Skip to content

Commit

Permalink
net/http: escape path in implicit /tree→/tree/ ServeMux.Handle redirect
Browse files Browse the repository at this point in the history
Fixes #10572

Change-Id: I764f3c226cf98ff39d9e553e4613d0ee108ef766
Reviewed-on: https://go-review.googlesource.com/9311
Reviewed-by: Russ Cox <[email protected]>
  • Loading branch information
Mihai Borobocea authored and rsc committed Jun 26, 2015
1 parent e6ad56c commit 450988b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/net/http/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ var handlers = []struct {
}{
{"/", "Default"},
{"/someDir/", "someDir"},
{"/#/", "hash"},
{"someHost.com/someDir/", "someHost.com/someDir"},
}

Expand All @@ -215,12 +216,14 @@ var vtests = []struct {
expected string
}{
{"http://localhost/someDir/apage", "someDir"},
{"http://localhost/%23/apage", "hash"},
{"http://localhost/otherDir/apage", "Default"},
{"http://someHost.com/someDir/apage", "someHost.com/someDir"},
{"http://otherHost.com/someDir/apage", "someDir"},
{"http://otherHost.com/aDir/apage", "Default"},
// redirections for trees
{"http://localhost/someDir", "/someDir/"},
{"http://localhost/%23", "/%23/"},
{"http://someHost.com/someDir", "/someDir/"},
}

Expand Down
3 changes: 2 additions & 1 deletion src/net/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,8 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
// strings.Index can't be -1.
path = pattern[strings.Index(pattern, "/"):]
}
mux.m[pattern[0:n-1]] = muxEntry{h: RedirectHandler(path, StatusMovedPermanently), pattern: pattern}
url := &url.URL{Path: path}
mux.m[pattern[0:n-1]] = muxEntry{h: RedirectHandler(url.String(), StatusMovedPermanently), pattern: pattern}
}
}

Expand Down

0 comments on commit 450988b

Please sign in to comment.