]> Cypherpunks repositories - gostls13.git/commitdiff
http: fix ParseURL to handle //relative_path properly
authorAndrew Gerrand <adg@golang.org>
Mon, 12 Jul 2010 23:21:42 +0000 (09:21 +1000)
committerAndrew Gerrand <adg@golang.org>
Mon, 12 Jul 2010 23:21:42 +0000 (09:21 +1000)
Fixes #900.

R=rsc
CC=golang-dev
https://golang.org/cl/1756042

src/pkg/http/url.go
src/pkg/http/url_test.go

index 148ada4b25858fc5b61d793afa4dbb2137c16926..12247ca17b801faef33df6218f704be7453d3ee1 100644 (file)
@@ -318,7 +318,7 @@ func ParseURL(rawurl string) (url *URL, err os.Error) {
        }
 
        // Maybe path is //authority/path
-       if len(path) > 2 && path[0:2] == "//" {
+       if url.Scheme != "" && len(path) > 2 && path[0:2] == "//" {
                url.Authority, path = split(path[2:], '/', false)
        }
        url.RawPath = path + query
index 3d665100af6ce498370e9edf84538144ba44c06c..097669b9c2ae64546edeeee1befc6108950a23ab 100644 (file)
@@ -174,6 +174,17 @@ var urltests = []URLTest{
                },
                "",
        },
+       // leading // without scheme shouldn't create an authority
+       URLTest{
+               "//foo",
+               &URL{
+                       Raw:     "//foo",
+                       Scheme:  "",
+                       RawPath: "//foo",
+                       Path:    "//foo",
+               },
+               "",
+       },
 }
 
 var urlnofragtests = []URLTest{