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
This commit is contained in:
parent
88c448ba40
commit
f41b43a024
@ -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))
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user