Skip to content

Commit

Permalink
net/url: fix JoinPath
Browse files Browse the repository at this point in the history
  • Loading branch information
earthboundkid committed Apr 5, 2022
1 parent 9e16cc1 commit 6342cca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/net/url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,11 @@ func (u *URL) JoinPath(elem ...string) *URL {
url := *u
if len(elem) > 0 {
elem = append([]string{u.Path}, elem...)
url.setPath(path.Join(elem...))
p := path.Join(elem...)
if strings.HasSuffix(elem[len(elem)-1], "/") {
p += "/"
}
url.setPath(p)
}
return &url
}
Expand Down
10 changes: 10 additions & 0 deletions src/net/url/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,16 @@ func TestJoinPath(t *testing.T) {
elem: []string{"/go", "a", "b", "c"},
out: "https://go.googlesource.com/go/a/b/c",
},
{
base: "https://go.googlesource.com/go/a/",
elem: []string{},
out: "https://go.googlesource.com/go/a/",
},
{
base: "https://go.googlesource.com/go/a/",
elem: []string{"b/"},
out: "https://go.googlesource.com/go/a/b/",
},
{
base: "http://[fe80::1%en0]:8080/",
elem: []string{"/go"},
Expand Down

0 comments on commit 6342cca

Please sign in to comment.