From 82e82be7604015509c78aeded28f94afa2e34a81 Mon Sep 17 00:00:00 2001 From: Alexandr Yolkin Date: Mon, 18 Apr 2022 14:27:52 +0300 Subject: [PATCH 1/3] - Allow parse etag without quotes --- .gitignore | 5 +++++ internal/elements.go | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a1338d6..e4fcdfb 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,8 @@ # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ + +# JetBrains GoLand +.idea +*.iml +*.ipr \ No newline at end of file diff --git a/internal/elements.go b/internal/elements.go index eb76842..2e1c1b0 100644 --- a/internal/elements.go +++ b/internal/elements.go @@ -342,7 +342,8 @@ 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) + *etag = ETag(b) + return nil } *etag = ETag(s) return nil From c9b61c2fa26ff7ae42402dbc34d76a0a9e5c5de6 Mon Sep 17 00:00:00 2001 From: Alexandr Yolkin Date: Tue, 3 May 2022 18:25:04 +0300 Subject: [PATCH 2/3] - Return etag "as is" --- .gitignore | 7 +------ internal/elements.go | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index e4fcdfb..35903bd 100644 --- a/.gitignore +++ b/.gitignore @@ -11,9 +11,4 @@ *.out # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 -.glide/ - -# JetBrains GoLand -.idea -*.iml -*.ipr \ No newline at end of file +.glide/ \ No newline at end of file diff --git a/internal/elements.go b/internal/elements.go index 2e1c1b0..f9291b7 100644 --- a/internal/elements.go +++ b/internal/elements.go @@ -340,12 +340,7 @@ type GetETag struct { type ETag string func (etag *ETag) UnmarshalText(b []byte) error { - s, err := strconv.Unquote(string(b)) - if err != nil { - *etag = ETag(b) - return nil - } - *etag = ETag(s) + *etag = ETag(b) return nil } From ae6a4e5952d30490bbec50c2772083dc80b94cb1 Mon Sep 17 00:00:00 2001 From: Alexandr Yolkin Date: Wed, 4 May 2022 09:57:10 +0300 Subject: [PATCH 3/3] - Remove UnmarshalText, MarshalText, String methods for eTag - Change separated type ETag to String --- .gitignore | 2 +- carddav/server.go | 4 ++-- internal/elements.go | 17 +---------------- server.go | 4 ++-- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 35903bd..a1338d6 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ *.out # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 -.glide/ \ No newline at end of file +.glide/ diff --git a/carddav/server.go b/carddav/server.go index a0e326d..ade1051 100644 --- a/carddav/server.go +++ b/carddav/server.go @@ -272,7 +272,7 @@ func (b *backend) HeadGet(w http.ResponseWriter, r *http.Request) error { w.Header().Set("Content-Type", vcard.MIMEType) if ao.ETag != "" { - w.Header().Set("ETag", internal.ETag(ao.ETag).String()) + w.Header().Set("ETag", ao.ETag) } if !ao.ModTime.IsZero() { w.Header().Set("Last-Modified", ao.ModTime.UTC().Format(http.TimeFormat)) @@ -392,7 +392,7 @@ func (b *backend) propfindAddressObject(propfind *internal.Propfind, ao *Address if ao.ETag != "" { props[internal.GetETagName] = func(*internal.RawXMLValue) (interface{}, error) { - return &internal.GetETag{ETag: internal.ETag(ao.ETag)}, nil + return &internal.GetETag{ETag: ao.ETag}, nil } } diff --git a/internal/elements.go b/internal/elements.go index f9291b7..fa717d9 100644 --- a/internal/elements.go +++ b/internal/elements.go @@ -334,22 +334,7 @@ type GetLastModified struct { // https://tools.ietf.org/html/rfc4918#section-15.6 type GetETag struct { XMLName xml.Name `xml:"DAV: getetag"` - ETag ETag `xml:",chardata"` -} - -type ETag string - -func (etag *ETag) UnmarshalText(b []byte) error { - *etag = ETag(b) - return nil -} - -func (etag ETag) MarshalText() ([]byte, error) { - return []byte(etag.String()), nil -} - -func (etag ETag) String() string { - return fmt.Sprintf("%q", string(etag)) + ETag string `xml:",chardata"` } // https://tools.ietf.org/html/rfc4918#section-14.5 diff --git a/server.go b/server.go index 811ef10..ee4cea4 100644 --- a/server.go +++ b/server.go @@ -92,7 +92,7 @@ func (b *backend) HeadGet(w http.ResponseWriter, r *http.Request) error { w.Header().Set("Last-Modified", fi.ModTime.UTC().Format(http.TimeFormat)) } if fi.ETag != "" { - w.Header().Set("ETag", internal.ETag(fi.ETag).String()) + w.Header().Set("ETag", fi.ETag) } if rs, ok := f.(io.ReadSeeker); ok { @@ -173,7 +173,7 @@ func (b *backend) propfindFile(propfind *internal.Propfind, fi *FileInfo) (*inte if fi.ETag != "" { props[internal.GetETagName] = func(*internal.RawXMLValue) (interface{}, error) { - return &internal.GetETag{ETag: internal.ETag(fi.ETag)}, nil + return &internal.GetETag{ETag: fi.ETag}, nil } } }