Commit f41b43a0 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/url: fix regression when serializing relative URLs

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
parent 88c448ba
...@@ -459,7 +459,7 @@ func (u *URL) String() string { ...@@ -459,7 +459,7 @@ func (u *URL) String() string {
buf.WriteString(h) buf.WriteString(h)
} }
} }
if u.Path != "" && u.Path[0] != '/' { if u.Path != "" && u.Path[0] != '/' && u.Host != "" {
buf.WriteByte('/') buf.WriteByte('/')
} }
buf.WriteString(escape(u.Path, encodePath)) buf.WriteString(escape(u.Path, encodePath))
......
...@@ -260,6 +260,14 @@ var urltests = []URLTest{ ...@@ -260,6 +260,14 @@ var urltests = []URLTest{
}, },
"mailto:webmaster@golang.org", "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 // more useful string for debugging than fmt's struct printer
......
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