]> Cypherpunks repositories - gostls13.git/commitdiff
net/url: fix regression when serializing relative URLs
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 17 Oct 2013 23:06:40 +0000 (16:06 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 17 Oct 2013 23:06:40 +0000 (16:06 -0700)
Only add a slash to path if it's a separator between
a host and path.

Fixes #6609

R=golang-dev, dsymonds, r
CC=golang-dev
https://golang.org/cl/14815043

src/pkg/net/url/url.go
src/pkg/net/url/url_test.go

index 95432f43376e7336f3fc166f86f042ed54a78a8a..597cb51c883074434b10eca555e5ba41a88e1dbf 100644 (file)
@@ -459,7 +459,7 @@ func (u *URL) String() string {
                                buf.WriteString(h)
                        }
                }
-               if u.Path != "" && u.Path[0] != '/' {
+               if u.Path != "" && u.Path[0] != '/' && u.Host != "" {
                        buf.WriteByte('/')
                }
                buf.WriteString(escape(u.Path, encodePath))
index 24f84e58ffe7a5b3d88bad1868ba2953c566dd12..7578eb15b907ba0bce2b3f207be6cc818b1eee36 100644 (file)
@@ -260,6 +260,14 @@ var urltests = []URLTest{
                },
                "mailto:webmaster@golang.org",
        },
+       // Relative path
+       {
+               "a/b/c",
+               &URL{
+                       Path: "a/b/c",
+               },
+               "a/b/c",
+       },
 }
 
 // more useful string for debugging than fmt's struct printer