internal: accomodate for trailign slashes in Multistatus.Get

This commit is contained in:
Simon Ser 2020-02-12 17:12:21 +01:00
parent 7f285fdf83
commit 0b2d0a706c
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"net/url"
"path"
"strconv"
"strings"
"time"
@ -98,17 +99,19 @@ func NewMultistatus(resps ...Response) *Multistatus {
return &Multistatus{Responses: resps}
}
func (ms *Multistatus) Get(path string) (*Response, error) {
func (ms *Multistatus) Get(p string) (*Response, error) {
// Clean the path to avoid issues with trailing slashes
p = path.Clean(p)
for i := range ms.Responses {
resp := &ms.Responses[i]
for _, h := range resp.Hrefs {
if h.Path == path {
if path.Clean(h.Path) == p {
return resp, resp.Status.Err()
}
}
}
return nil, fmt.Errorf("webdav: missing response for path %q", path)
return nil, fmt.Errorf("webdav: missing response for path %q", p)
}
// https://tools.ietf.org/html/rfc4918#section-14.24