]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: escape path in implicit /tree→/tree/ ServeMux.Handle redirect
authorMihai Borobocea <MihaiBorobocea@gmail.com>
Fri, 24 Apr 2015 18:47:25 +0000 (21:47 +0300)
committerRuss Cox <rsc@golang.org>
Fri, 26 Jun 2015 18:32:40 +0000 (18:32 +0000)
Fixes #10572

Change-Id: I764f3c226cf98ff39d9e553e4613d0ee108ef766
Reviewed-on: https://go-review.googlesource.com/9311
Reviewed-by: Russ Cox <rsc@golang.org>
src/net/http/serve_test.go
src/net/http/server.go

index de40559ff1939671083546c7d426083a288ecdc3..02f1dbf20a798da28378f7fcbd5f8da7fdcad04e 100644 (file)
@@ -207,6 +207,7 @@ var handlers = []struct {
 }{
        {"/", "Default"},
        {"/someDir/", "someDir"},
+       {"/#/", "hash"},
        {"someHost.com/someDir/", "someHost.com/someDir"},
 }
 
@@ -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/"},
 }
 
index 71154ec2be5ff8345556de609fb1f017d1ed00e7..bac3e0464737c873dff6304a5876e398333d4bfd 100644 (file)
@@ -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}
        }
 }