mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-23 00:34:23 +00:00
webdav: fix propfind decode errors
This commit is contained in:
parent
1be15ec875
commit
e36c7881da
18
xml.go
18
xml.go
@ -14,6 +14,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo
|
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo
|
||||||
@ -105,15 +106,24 @@ func next(d *xml.Decoder) (xml.Token, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return t, err
|
return t, err
|
||||||
}
|
}
|
||||||
switch t.(type) {
|
switch t := t.(type) {
|
||||||
case xml.Comment, xml.Directive, xml.ProcInst:
|
case xml.Comment, xml.Directive, xml.ProcInst:
|
||||||
continue
|
continue
|
||||||
|
case xml.CharData:
|
||||||
|
for _, c := range t {
|
||||||
|
if !unicode.IsSpace(rune(c)) {
|
||||||
|
return t, fmt.Errorf("unexpected non-empty xml.CharData")
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return t, nil
|
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)
|
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for propfind)
|
||||||
type PropfindProps []xml.Name
|
type PropfindProps []xml.Name
|
||||||
|
|
||||||
@ -135,13 +145,9 @@ func (pn *PropfindProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er
|
|||||||
return nil
|
return nil
|
||||||
case xml.StartElement:
|
case xml.StartElement:
|
||||||
name := t.(xml.StartElement).Name
|
name := t.(xml.StartElement).Name
|
||||||
t, err = next(d)
|
if err := d.Skip(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, ok := t.(xml.EndElement); !ok {
|
|
||||||
return fmt.Errorf("unexpected token %T", t)
|
|
||||||
}
|
|
||||||
*pn = append(*pn, xml.Name(name))
|
*pn = append(*pn, xml.Name(name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user