Commit 450988b5 authored by Mihai Borobocea's avatar Mihai Borobocea Committed by Russ Cox

net/http: escape path in implicit /tree→/tree/ ServeMux.Handle redirect

Fixes #10572

Change-Id: I764f3c226cf98ff39d9e553e4613d0ee108ef766
Reviewed-on: https://go-review.googlesource.com/9311Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent e6ad56c7
...@@ -207,6 +207,7 @@ var handlers = []struct { ...@@ -207,6 +207,7 @@ var handlers = []struct {
}{ }{
{"/", "Default"}, {"/", "Default"},
{"/someDir/", "someDir"}, {"/someDir/", "someDir"},
{"/#/", "hash"},
{"someHost.com/someDir/", "someHost.com/someDir"}, {"someHost.com/someDir/", "someHost.com/someDir"},
} }
...@@ -215,12 +216,14 @@ var vtests = []struct { ...@@ -215,12 +216,14 @@ var vtests = []struct {
expected string expected string
}{ }{
{"http://localhost/someDir/apage", "someDir"}, {"http://localhost/someDir/apage", "someDir"},
{"http://localhost/%23/apage", "hash"},
{"http://localhost/otherDir/apage", "Default"}, {"http://localhost/otherDir/apage", "Default"},
{"http://someHost.com/someDir/apage", "someHost.com/someDir"}, {"http://someHost.com/someDir/apage", "someHost.com/someDir"},
{"http://otherHost.com/someDir/apage", "someDir"}, {"http://otherHost.com/someDir/apage", "someDir"},
{"http://otherHost.com/aDir/apage", "Default"}, {"http://otherHost.com/aDir/apage", "Default"},
// redirections for trees // redirections for trees
{"http://localhost/someDir", "/someDir/"}, {"http://localhost/someDir", "/someDir/"},
{"http://localhost/%23", "/%23/"},
{"http://someHost.com/someDir", "/someDir/"}, {"http://someHost.com/someDir", "/someDir/"},
} }
......
...@@ -1667,7 +1667,8 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) { ...@@ -1667,7 +1667,8 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
// strings.Index can't be -1. // strings.Index can't be -1.
path = pattern[strings.Index(pattern, "/"):] 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}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment