From: Brad Fitzpatrick Date: Thu, 17 Oct 2013 23:06:40 +0000 (-0700) Subject: net/url: fix regression when serializing relative URLs X-Git-Tag: go1.2rc2~3 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f41b43a02431baab166d06b8b4c41467d9cc88e4;p=gostls13.git 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 --- 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