Skip to content

Commit

Permalink
ocdav: Fix parsing of PROPPATCH properties (#743)
Browse files Browse the repository at this point in the history
Use the parent struct when parsing to make sure the decoder finds the
hint about "innerxml" parsing mode for proppatch properties,
and prevents mangling of said values when they contain an "xmlns"
attribute.
  • Loading branch information
Vincent Petry authored May 15, 2020
1 parent 2e91d9f commit a51ce34
Showing 1 changed file with 4 additions and 35 deletions.
39 changes: 4 additions & 35 deletions internal/http/services/owncloud/ocdav/proppatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package ocdav

import (
"bytes"
"encoding/xml"
"fmt"
"io"
Expand Down Expand Up @@ -213,35 +212,6 @@ type Proppatch struct {
Props []propertyXML
}

type xmlValue []byte

func (v *xmlValue) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// The XML value of a property can be arbitrary, mixed-content XML.
// To make sure that the unmarshalled value contains all required
// namespaces, we encode all the property value XML tokens into a
// buffer. This forces the encoder to redeclare any used namespaces.
var b bytes.Buffer
e := xml.NewEncoder(&b)
for {
t, err := next(d)
if err != nil {
return err
}
if e, ok := t.(xml.EndElement); ok && e.Name == start.Name {
break
}
if err = e.EncodeToken(t); err != nil {
return err
}
}
err := e.Flush()
if err != nil {
return err
}
*v = b.Bytes()
return nil
}

// http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for proppatch)
type proppatchProps []propertyXML

Expand All @@ -267,14 +237,13 @@ func (ps *proppatchProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) e
}
return nil
case xml.StartElement:
p := propertyXML{
XMLName: t.(xml.StartElement).Name,
Lang: xmlLang(t.(xml.StartElement), lang),
}
err = d.DecodeElement(((*xmlValue)(&p.InnerXML)), &elem)
p := propertyXML{}
err = d.DecodeElement(&p, &elem)
if err != nil {
return err
}
// special handling for the lang property
p.Lang = xmlLang(t.(xml.StartElement), lang)
*ps = append(*ps, p)
}
}
Expand Down

0 comments on commit a51ce34

Please sign in to comment.