From f41b43a02431baab166d06b8b4c41467d9cc88e4 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 17 Oct 2013 16:06:40 -0700 Subject: [PATCH] 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 --- src/pkg/net/url/url.go | 2 +- src/pkg/net/url/url_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 -- 2.50.0