mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
398dcd1cf0
commit
bf5898ef53
2 changed files with 11 additions and 1 deletions
|
|
@ -1193,7 +1193,7 @@ func (u *URL) UnmarshalBinary(text []byte) error {
|
||||||
func (u *URL) JoinPath(elem ...string) *URL {
|
func (u *URL) JoinPath(elem ...string) *URL {
|
||||||
url := *u
|
url := *u
|
||||||
if len(elem) > 0 {
|
if len(elem) > 0 {
|
||||||
elem = append([]string{u.Path}, elem...)
|
elem = append([]string{u.EscapedPath()}, elem...)
|
||||||
p := path.Join(elem...)
|
p := path.Join(elem...)
|
||||||
// path.Join will remove any trailing slashes.
|
// path.Join will remove any trailing slashes.
|
||||||
// Preserve at least one.
|
// Preserve at least one.
|
||||||
|
|
|
||||||
|
|
@ -2119,6 +2119,16 @@ func TestJoinPath(t *testing.T) {
|
||||||
elem: nil,
|
elem: nil,
|
||||||
out: "https://go.googlesource.com/",
|
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: "/",
|
base: "/",
|
||||||
elem: nil,
|
elem: nil,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue