src/pkg/net/url/url.go | 2 +- src/pkg/net/url/url_test.go | 8 ++++++++ diff --git a/src/pkg/net/url/url.go b/src/pkg/net/url/url.go index 95432f43376e7336f3fc166f86f042ed54a78a8a..597cb51c883074434b10eca555e5ba41a88e1dbf 100644 --- a/src/pkg/net/url/url.go +++ b/src/pkg/net/url/url.go @@ -459,7 +459,7 @@ if h := u.Host; h != "" { 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 24f84e58ffe7a5b3d88bad1868ba2953c566dd12..7578eb15b907ba0bce2b3f207be6cc818b1eee36 100644 --- a/src/pkg/net/url/url_test.go +++ b/src/pkg/net/url/url_test.go @@ -260,6 +260,14 @@ Opaque: "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