diff options
author | Mark Theunissen <mark.theunissen@gmail.com> | 2017-07-25 12:47:39 +0200 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2017-10-30 21:00:06 +0000 |
commit | 84e91e1d6b2fed3e19d69194067cc2797f503b95 (patch) | |
tree | e54690049b9b52630e606d0c14cc2b05b080ddf0 /src | |
parent | b4c3fe7b049f79f81fae52d5006aa29b926bb4e0 (diff) | |
download | go-git-84e91e1d6b2fed3e19d69194067cc2797f503b95.tar.gz |
net/url: preserve leading slashes when resolving path
When doing resolvePath, if there are multiple leading slashes in the
target, preserve them. This prevents an issue where the Go http.Client
cleans up multiple leading slashes in the Location header in a
redirect, resulting in a redirection to the incorrect target.
Fixes #21158.
Change-Id: I6a21ea61ca3bc7033f3c8a6ccc21ecaa3e996fa8
Reviewed-on: https://go-review.googlesource.com/51050
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/net/url/url.go | 2 | ||||
-rw-r--r-- | src/net/url/url_test.go | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/net/url/url.go b/src/net/url/url.go index c9353ab080..509cec3ba0 100644 --- a/src/net/url/url.go +++ b/src/net/url/url.go @@ -911,7 +911,7 @@ func resolvePath(base, ref string) string { // Add final slash to the joined path. dst = append(dst, "") } - return "/" + strings.TrimLeft(strings.Join(dst, "/"), "/") + return "/" + strings.TrimPrefix(strings.Join(dst, "/"), "/") } // IsAbs reports whether the URL is absolute. diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go index 5f03200d94..604b323601 100644 --- a/src/net/url/url_test.go +++ b/src/net/url/url_test.go @@ -1032,6 +1032,10 @@ var resolveReferenceTests = []struct { {"http://foo.com/bar?a=b", "/baz?", "http://foo.com/baz?"}, {"http://foo.com/bar?a=b", "/baz?c=d", "http://foo.com/baz?c=d"}, + // Multiple slashes + {"http://foo.com/bar", "http://foo.com//baz", "http://foo.com//baz"}, + {"http://foo.com/bar", "http://foo.com///baz/quux", "http://foo.com///baz/quux"}, + // Scheme-relative {"https://foo.com/bar?a=b", "//bar.com/quux", "https://bar.com/quux"}, |