Commit 6dc0abcc authored by Robert Stepanek's avatar Robert Stepanek Committed by Nigel Tao

webdav: fix XML golden tests for encoding/xml xmlns change.

The change to the standard encoding/xml library was
https://go-review.googlesource.com/#/c/2660/
which landed on 2015-02-14. An additional change was
https://go-review.googlesource.com/#/c/5910/ which
landed on 2015-03-03.

Fixes #9978.

Change-Id: I4f798f153e4e13b13eadc10e44b21a4b118251d3
Reviewed-on: https://go-review.googlesource.com/5714Reviewed-by: 's avatarNigel Tao <nigeltao@golang.org>
parent 3d87fd62
......@@ -212,12 +212,7 @@ type xmlError struct {
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_propstat
type propstat struct {
// Prop requires DAV: to be the default namespace in the enclosing
// XML. This is due to the standard encoding/xml package currently
// not honoring namespace declarations inside a xmltag with a
// parent element for anonymous slice elements.
// Use of multistatusWriter takes care of this.
Prop []Property `xml:"prop>_ignored_"`
Prop []Property `xml:"DAV: prop>_ignored_"`
Status string `xml:"DAV: status"`
Error *xmlError `xml:"DAV: error"`
ResponseDescription string `xml:"DAV: responsedescription,omitempty"`
......@@ -271,12 +266,24 @@ func (w *multistatusWriter) write(r *response) error {
if w.enc == nil {
w.w.Header().Add("Content-Type", "text/xml; charset=utf-8")
w.w.WriteHeader(StatusMulti)
_, err := fmt.Fprintf(w.w, `<?xml version="1.0" encoding="UTF-8"?>`+
`<D:multistatus xmlns:D="DAV:">`)
_, err := fmt.Fprintf(w.w, `<?xml version="1.0" encoding="UTF-8"?>`)
if err != nil {
return err
}
w.enc = xml.NewEncoder(w.w)
err = w.enc.EncodeToken(xml.StartElement{
Name: xml.Name{
Space: "DAV:",
Local: "multistatus",
},
Attr: []xml.Attr{{
Name: xml.Name{Local: "xmlns"},
Value: "DAV:",
}},
})
if err != nil {
return err
}
}
return w.enc.Encode(r)
}
......@@ -289,14 +296,23 @@ func (w *multistatusWriter) close() error {
if w.enc == nil {
return nil
}
var end []xml.Token
if w.responseDescription != "" {
_, err := fmt.Fprintf(w.w,
"<D:responsedescription>%s</D:responsedescription>",
w.responseDescription)
name := xml.Name{Space: "DAV:", Local: "responsedescription"}
end = append(end,
xml.StartElement{Name: name},
xml.CharData(w.responseDescription),
xml.EndElement{Name: name},
)
}
end = append(end, xml.EndElement{
Name: xml.Name{Space: "DAV:", Local: "multistatus"},
})
for _, t := range end {
err := w.enc.EncodeToken(t)
if err != nil {
return err
}
}
_, err := fmt.Fprintf(w.w, "</D:multistatus>")
return err
return w.enc.Flush()
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment