]> Cypherpunks repositories - gostls13.git/commit
net/url: consider an empty base Path as equivalent to / in JoinPath
authorDamien Neil <dneil@google.com>
Tue, 21 Feb 2023 19:24:56 +0000 (11:24 -0800)
committerDamien Neil <dneil@google.com>
Fri, 8 Mar 2024 17:01:05 +0000 (17:01 +0000)
commita46285f8c2389b92952c1484daacfccf70a17047
treea77cdc200237c054b016f51219de2fa9c1568d86
parentc8c46e746b778c39727c588adf79aff34ab6f151
net/url: consider an empty base Path as equivalent to / in JoinPath

A Path that starts with / is absolute.
A Path that starts with any other character is relative.

The meaning of a Path of "" is not defined,
but RequestURI converts a "" Path to "/"
and an empty Path may represent a URL with just
a hostname and no trailing / such as "http://localhost".

Handle empty paths in the base URL of JoinPath consistently with
RequestURI, so that joining to an empty base produces an absolute
path rather than a relative one.

u, _ := url.Parse("http://localhost")
u = u.JoinPath("x")
fmt.Println(u.Path) // "/x", not "x"

Fixes #58605

Change-Id: Iacced9c173b0aa693800dd01caf774f3f9a66d56
Reviewed-on: https://go-review.googlesource.com/c/go/+/469935
Reviewed-by: Jonathan Amsterdam <jba@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/net/url/url.go
src/net/url/url_test.go