Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions internal/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,16 @@ type GetETag struct {
type ETag string

func (etag *ETag) UnmarshalText(b []byte) error {
s, err := strconv.Unquote(string(b))
if err != nil {
return fmt.Errorf("webdav: failed to unquote ETag: %v", err)
s := string(b)
if (s[0:1] == "\"") {
sUnquoted, err := strconv.Unquote(s)
if err != nil {
return fmt.Errorf("webdav: failed to unquote ETag: %v", err)
}
*etag = ETag(sUnquoted)
} else {
*etag = ETag(s)
}
*etag = ETag(s)
return nil
}

Expand Down
16 changes: 16 additions & 0 deletions internal/elements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,19 @@ func TestTimeRoundTrip(t *testing.T) {
t.Fatalf("invalid round-trip:\ngot= %s\nwant=%s", got, want)
}
}

func TestETagUnmarshalText(t *testing.T) {
quotedEtag := `"123"`

var got ETag
err := got.UnmarshalText([]byte(quotedEtag))
if err != nil {
t.Fatalf("UnmarshalText failed for ETag: %+v", err)
}

unquotedEtag := "123"
err = got.UnmarshalText([]byte(unquotedEtag))
if err != nil {
t.Fatalf("UnmarshalText failed for ETag: %+v", err)
}
}