internal: preserve trailing slashes in baseURL and principal path

Closes: https://github.com/emersion/go-webdav/issues/203
This commit is contained in:
Ruben Aleman 2026-04-11 12:38:55 +02:00 committed by GitHub
parent 1916c2d907
commit 0463911636
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -110,9 +110,16 @@ func NewClient(c HTTPClient, endpoint string) (*Client, error) {
}
func (c *Client) ResolveHref(p string) *url.URL {
hasTrailingSlash := strings.HasSuffix(p, "/") || (p == "" && strings.HasSuffix(c.endpoint.Path, "/"))
if !strings.HasPrefix(p, "/") {
p = path.Join(c.endpoint.Path, p)
}
if hasTrailingSlash && !strings.HasSuffix(p, "/") {
p += "/"
}
return &url.URL{
Scheme: c.endpoint.Scheme,
User: c.endpoint.User,