Skip to content

Commit daaf947

Browse files
seankhliaojproberts
authored andcommitted
net/url: use EscapedPath for url.JoinPath
Fixes golang#53763 Change-Id: I08b53f159ebdce7907e8cc17316fd0c982363239 Reviewed-on: https://go-review.googlesource.com/c/go/+/416774 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent 48e73c6 commit daaf947

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/net/url/url.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ func (u *URL) UnmarshalBinary(text []byte) error {
11931193
func (u *URL) JoinPath(elem ...string) *URL {
11941194
url := *u
11951195
if len(elem) > 0 {
1196-
elem = append([]string{u.Path}, elem...)
1196+
elem = append([]string{u.EscapedPath()}, elem...)
11971197
p := path.Join(elem...)
11981198
// path.Join will remove any trailing slashes.
11991199
// Preserve at least one.

src/net/url/url_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,16 @@ func TestJoinPath(t *testing.T) {
21192119
elem: nil,
21202120
out: "https://go.googlesource.com/",
21212121
},
2122+
{
2123+
base: "https://go.googlesource.com/a%2fb",
2124+
elem: []string{"c"},
2125+
out: "https://go.googlesource.com/a%2fb/c",
2126+
},
2127+
{
2128+
base: "https://go.googlesource.com/a%2fb",
2129+
elem: []string{"c%2fd"},
2130+
out: "https://go.googlesource.com/a%2fb/c%2fd",
2131+
},
21222132
{
21232133
base: "/",
21242134
elem: nil,

0 commit comments

Comments
 (0)