diff options
author | Sean Liao <sean@liao.dev> | 2022-07-09 18:38:45 +0100 |
---|---|---|
committer | Damien Neil <dneil@google.com> | 2022-07-11 18:09:14 +0000 |
commit | bf5898ef53d1693aa572da0da746c05e9a6f15c5 (patch) | |
tree | 0b92e47c69767dfd284729f4680d256642adc88b | |
parent | 398dcd1cf00a1536dad98cf87c16f8ad0c8913fc (diff) | |
download | go-bf5898ef53d1693aa572da0da746c05e9a6f15c5.tar.gz go-bf5898ef53d1693aa572da0da746c05e9a6f15c5.zip |
net/url: use EscapedPath for url.JoinPath
Fixes #53763
Change-Id: I08b53f159ebdce7907e8cc17316fd0c982363239
Reviewed-on: https://go-review.googlesource.com/c/go/+/416774
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
-rw-r--r-- | src/net/url/url.go | 2 | ||||
-rw-r--r-- | src/net/url/url_test.go | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/net/url/url.go b/src/net/url/url.go index db4d6385e3..e82ae6aeef 100644 --- a/src/net/url/url.go +++ b/src/net/url/url.go @@ -1193,7 +1193,7 @@ func (u *URL) UnmarshalBinary(text []byte) error { func (u *URL) JoinPath(elem ...string) *URL { url := *u if len(elem) > 0 { - elem = append([]string{u.Path}, elem...) + elem = append([]string{u.EscapedPath()}, elem...) p := path.Join(elem...) // path.Join will remove any trailing slashes. // Preserve at least one. diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go index 478cc34872..263eddffcf 100644 --- a/src/net/url/url_test.go +++ b/src/net/url/url_test.go @@ -2120,6 +2120,16 @@ func TestJoinPath(t *testing.T) { out: "https://go.googlesource.com/", }, { + base: "https://go.googlesource.com/a%2fb", + elem: []string{"c"}, + out: "https://go.googlesource.com/a%2fb/c", + }, + { + base: "https://go.googlesource.com/a%2fb", + elem: []string{"c%2fd"}, + out: "https://go.googlesource.com/a%2fb/c%2fd", + }, + { base: "/", elem: nil, out: "/", |