Skip to content

Commit

Permalink
webdav: fix propfind decode errors
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Jan 8, 2020
1 parent 1be15ec commit e36c788
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"io"
"net/http"
"time"
"unicode"
)

// http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo
Expand Down Expand Up @@ -105,15 +106,24 @@ func next(d *xml.Decoder) (xml.Token, error) {
if err != nil {
return t, err
}
switch t.(type) {
switch t := t.(type) {
case xml.Comment, xml.Directive, xml.ProcInst:
continue
case xml.CharData:
for _, c := range t {
if !unicode.IsSpace(rune(c)) {
return t, fmt.Errorf("unexpected non-empty xml.CharData")
}
}
default:
return t, nil
}
}
}

// TODO: the xml.Name isn't enough, enclosed elements matter too (e.g.
// CardDAV's address-data)

// http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for propfind)
type PropfindProps []xml.Name

Expand All @@ -135,13 +145,9 @@ func (pn *PropfindProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er
return nil
case xml.StartElement:
name := t.(xml.StartElement).Name
t, err = next(d)
if err != nil {
if err := d.Skip(); err != nil {
return err
}
if _, ok := t.(xml.EndElement); !ok {
return fmt.Errorf("unexpected token %T", t)
}
*pn = append(*pn, xml.Name(name))
}
}
Expand Down

0 comments on commit e36c788

Please sign in to comment.