aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2013-10-17 16:06:40 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2013-10-17 16:06:40 -0700
commitf41b43a02431baab166d06b8b4c41467d9cc88e4 (patch)
tree1340b15b9d124f30eae3097d0319d924f5479a72
parent88c448ba40a29ac96563e9945d2af17fba779d23 (diff)
downloadgo-f41b43a02431baab166d06b8b4c41467d9cc88e4.tar.gz
go-f41b43a02431baab166d06b8b4c41467d9cc88e4.zip
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
-rw-r--r--src/pkg/net/url/url.go2
-rw-r--r--src/pkg/net/url/url_test.go8
2 files changed, 9 insertions, 1 deletions
diff --git a/src/pkg/net/url/url.go b/src/pkg/net/url/url.go
index 95432f4337..597cb51c88 100644
--- a/src/pkg/net/url/url.go
+++ b/src/pkg/net/url/url.go
@@ -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))
diff --git a/src/pkg/net/url/url_test.go b/src/pkg/net/url/url_test.go
index 24f84e58ff..7578eb15b9 100644
--- a/src/pkg/net/url/url_test.go
+++ b/src/pkg/net/url/url_test.go
@@ -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