Commit 8f3641de authored by Nigel Tao's avatar Nigel Tao

webdav: rename the "etc/internal/xml" import.

There is no semantic change to this commit. A follow-up commit will
change this package's behavior, but this preparatory commit will make
the follow-up's diff smaller, and less noisy.

Change-Id: I12e356fc1f29d3c4a7c3374aab4a1b1eefe01144
Reviewed-on: https://go-review.googlesource.com/21631Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
parent bcb71dd1
...@@ -14,12 +14,12 @@ import ( ...@@ -14,12 +14,12 @@ import (
"net/http" "net/http"
"time" "time"
"golang.org/x/net/webdav/internal/xml" ixml "golang.org/x/net/webdav/internal/xml"
) )
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo // http://www.webdav.org/specs/rfc4918.html#ELEMENT_lockinfo
type lockInfo struct { type lockInfo struct {
XMLName xml.Name `xml:"lockinfo"` XMLName ixml.Name `xml:"lockinfo"`
Exclusive *struct{} `xml:"lockscope>exclusive"` Exclusive *struct{} `xml:"lockscope>exclusive"`
Shared *struct{} `xml:"lockscope>shared"` Shared *struct{} `xml:"lockscope>shared"`
Write *struct{} `xml:"locktype>write"` Write *struct{} `xml:"locktype>write"`
...@@ -33,7 +33,7 @@ type owner struct { ...@@ -33,7 +33,7 @@ type owner struct {
func readLockInfo(r io.Reader) (li lockInfo, status int, err error) { func readLockInfo(r io.Reader) (li lockInfo, status int, err error) {
c := &countingReader{r: r} c := &countingReader{r: r}
if err = xml.NewDecoder(c).Decode(&li); err != nil { if err = ixml.NewDecoder(c).Decode(&li); err != nil {
if err == io.EOF { if err == io.EOF {
if c.n == 0 { if c.n == 0 {
// An empty body means to refresh the lock. // An empty body means to refresh the lock.
...@@ -88,7 +88,7 @@ func escape(s string) string { ...@@ -88,7 +88,7 @@ func escape(s string) string {
switch s[i] { switch s[i] {
case '"', '&', '\'', '<', '>': case '"', '&', '\'', '<', '>':
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
xml.EscapeText(b, []byte(s)) ixml.EscapeText(b, []byte(s))
return b.String() return b.String()
} }
} }
...@@ -100,14 +100,14 @@ func escape(s string) string { ...@@ -100,14 +100,14 @@ func escape(s string) string {
// and directives. // and directives.
// http://www.webdav.org/specs/rfc4918.html#property_values // http://www.webdav.org/specs/rfc4918.html#property_values
// http://www.webdav.org/specs/rfc4918.html#xml-extensibility // http://www.webdav.org/specs/rfc4918.html#xml-extensibility
func next(d *xml.Decoder) (xml.Token, error) { func next(d *ixml.Decoder) (ixml.Token, error) {
for { for {
t, err := d.Token() t, err := d.Token()
if err != nil { if err != nil {
return t, err return t, err
} }
switch t.(type) { switch t.(type) {
case xml.Comment, xml.Directive, xml.ProcInst: case ixml.Comment, ixml.Directive, ixml.ProcInst:
continue continue
default: default:
return t, nil return t, nil
...@@ -116,31 +116,31 @@ func next(d *xml.Decoder) (xml.Token, error) { ...@@ -116,31 +116,31 @@ func next(d *xml.Decoder) (xml.Token, error) {
} }
// 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 []ixml.Name
// UnmarshalXML appends the property names enclosed within start to pn. // UnmarshalXML appends the property names enclosed within start to pn.
// //
// It returns an error if start does not contain any properties or if // It returns an error if start does not contain any properties or if
// properties contain values. Character data between properties is ignored. // properties contain values. Character data between properties is ignored.
func (pn *propfindProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (pn *propfindProps) UnmarshalXML(d *ixml.Decoder, start ixml.StartElement) error {
for { for {
t, err := next(d) t, err := next(d)
if err != nil { if err != nil {
return err return err
} }
switch t.(type) { switch t.(type) {
case xml.EndElement: case ixml.EndElement:
if len(*pn) == 0 { if len(*pn) == 0 {
return fmt.Errorf("%s must not be empty", start.Name.Local) return fmt.Errorf("%s must not be empty", start.Name.Local)
} }
return nil return nil
case xml.StartElement: case ixml.StartElement:
name := t.(xml.StartElement).Name name := t.(ixml.StartElement).Name
t, err = next(d) t, err = next(d)
if err != nil { if err != nil {
return err return err
} }
if _, ok := t.(xml.EndElement); !ok { if _, ok := t.(ixml.EndElement); !ok {
return fmt.Errorf("unexpected token %T", t) return fmt.Errorf("unexpected token %T", t)
} }
*pn = append(*pn, name) *pn = append(*pn, name)
...@@ -150,7 +150,7 @@ func (pn *propfindProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er ...@@ -150,7 +150,7 @@ func (pn *propfindProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_propfind // http://www.webdav.org/specs/rfc4918.html#ELEMENT_propfind
type propfind struct { type propfind struct {
XMLName xml.Name `xml:"DAV: propfind"` XMLName ixml.Name `xml:"DAV: propfind"`
Allprop *struct{} `xml:"DAV: allprop"` Allprop *struct{} `xml:"DAV: allprop"`
Propname *struct{} `xml:"DAV: propname"` Propname *struct{} `xml:"DAV: propname"`
Prop propfindProps `xml:"DAV: prop"` Prop propfindProps `xml:"DAV: prop"`
...@@ -159,7 +159,7 @@ type propfind struct { ...@@ -159,7 +159,7 @@ type propfind struct {
func readPropfind(r io.Reader) (pf propfind, status int, err error) { func readPropfind(r io.Reader) (pf propfind, status int, err error) {
c := countingReader{r: r} c := countingReader{r: r}
if err = xml.NewDecoder(&c).Decode(&pf); err != nil { if err = ixml.NewDecoder(&c).Decode(&pf); err != nil {
if err == io.EOF { if err == io.EOF {
if c.n == 0 { if c.n == 0 {
// An empty body means to propfind allprop. // An empty body means to propfind allprop.
...@@ -190,7 +190,7 @@ func readPropfind(r io.Reader) (pf propfind, status int, err error) { ...@@ -190,7 +190,7 @@ func readPropfind(r io.Reader) (pf propfind, status int, err error) {
// See http://www.webdav.org/specs/rfc4918.html#data.model.for.resource.properties // See http://www.webdav.org/specs/rfc4918.html#data.model.for.resource.properties
type Property struct { type Property struct {
// XMLName is the fully qualified name that identifies this property. // XMLName is the fully qualified name that identifies this property.
XMLName xml.Name XMLName ixml.Name
// Lang is an optional xml:lang attribute. // Lang is an optional xml:lang attribute.
Lang string `xml:"xml:lang,attr,omitempty"` Lang string `xml:"xml:lang,attr,omitempty"`
...@@ -209,7 +209,7 @@ type Property struct { ...@@ -209,7 +209,7 @@ type Property struct {
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_error // http://www.webdav.org/specs/rfc4918.html#ELEMENT_error
// See multistatusWriter for the "D:" namespace prefix. // See multistatusWriter for the "D:" namespace prefix.
type xmlError struct { type xmlError struct {
XMLName xml.Name `xml:"D:error"` XMLName ixml.Name `xml:"D:error"`
InnerXML []byte `xml:",innerxml"` InnerXML []byte `xml:",innerxml"`
} }
...@@ -224,10 +224,10 @@ type propstat struct { ...@@ -224,10 +224,10 @@ type propstat struct {
// MarshalXML prepends the "D:" namespace prefix on properties in the DAV: namespace // MarshalXML prepends the "D:" namespace prefix on properties in the DAV: namespace
// before encoding. See multistatusWriter. // before encoding. See multistatusWriter.
func (ps propstat) MarshalXML(e *xml.Encoder, start xml.StartElement) error { func (ps propstat) MarshalXML(e *ixml.Encoder, start ixml.StartElement) error {
for k, prop := range ps.Prop { for k, prop := range ps.Prop {
if prop.XMLName.Space == "DAV:" { if prop.XMLName.Space == "DAV:" {
prop.XMLName = xml.Name{Space: "", Local: "D:" + prop.XMLName.Local} prop.XMLName = ixml.Name{Space: "", Local: "D:" + prop.XMLName.Local}
ps.Prop[k] = prop ps.Prop[k] = prop
} }
} }
...@@ -239,7 +239,7 @@ func (ps propstat) MarshalXML(e *xml.Encoder, start xml.StartElement) error { ...@@ -239,7 +239,7 @@ func (ps propstat) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_response // http://www.webdav.org/specs/rfc4918.html#ELEMENT_response
// See multistatusWriter for the "D:" namespace prefix. // See multistatusWriter for the "D:" namespace prefix.
type response struct { type response struct {
XMLName xml.Name `xml:"D:response"` XMLName ixml.Name `xml:"D:response"`
Href []string `xml:"D:href"` Href []string `xml:"D:href"`
Propstat []propstat `xml:"D:propstat"` Propstat []propstat `xml:"D:propstat"`
Status string `xml:"D:status,omitempty"` Status string `xml:"D:status,omitempty"`
...@@ -264,7 +264,7 @@ type multistatusWriter struct { ...@@ -264,7 +264,7 @@ type multistatusWriter struct {
responseDescription string responseDescription string
w http.ResponseWriter w http.ResponseWriter
enc *xml.Encoder enc *ixml.Encoder
} }
// Write validates and emits a DAV response as part of a multistatus response // Write validates and emits a DAV response as part of a multistatus response
...@@ -308,14 +308,14 @@ func (w *multistatusWriter) writeHeader() error { ...@@ -308,14 +308,14 @@ func (w *multistatusWriter) writeHeader() error {
if err != nil { if err != nil {
return err return err
} }
w.enc = xml.NewEncoder(w.w) w.enc = ixml.NewEncoder(w.w)
return w.enc.EncodeToken(xml.StartElement{ return w.enc.EncodeToken(ixml.StartElement{
Name: xml.Name{ Name: ixml.Name{
Space: "DAV:", Space: "DAV:",
Local: "multistatus", Local: "multistatus",
}, },
Attr: []xml.Attr{{ Attr: []ixml.Attr{{
Name: xml.Name{Space: "xmlns", Local: "D"}, Name: ixml.Name{Space: "xmlns", Local: "D"},
Value: "DAV:", Value: "DAV:",
}}, }},
}) })
...@@ -329,17 +329,17 @@ func (w *multistatusWriter) close() error { ...@@ -329,17 +329,17 @@ func (w *multistatusWriter) close() error {
if w.enc == nil { if w.enc == nil {
return nil return nil
} }
var end []xml.Token var end []ixml.Token
if w.responseDescription != "" { if w.responseDescription != "" {
name := xml.Name{Space: "DAV:", Local: "responsedescription"} name := ixml.Name{Space: "DAV:", Local: "responsedescription"}
end = append(end, end = append(end,
xml.StartElement{Name: name}, ixml.StartElement{Name: name},
xml.CharData(w.responseDescription), ixml.CharData(w.responseDescription),
xml.EndElement{Name: name}, ixml.EndElement{Name: name},
) )
} }
end = append(end, xml.EndElement{ end = append(end, ixml.EndElement{
Name: xml.Name{Space: "DAV:", Local: "multistatus"}, Name: ixml.Name{Space: "DAV:", Local: "multistatus"},
}) })
for _, t := range end { for _, t := range end {
err := w.enc.EncodeToken(t) err := w.enc.EncodeToken(t)
...@@ -353,9 +353,9 @@ func (w *multistatusWriter) close() error { ...@@ -353,9 +353,9 @@ func (w *multistatusWriter) close() error {
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for proppatch) // http://www.webdav.org/specs/rfc4918.html#ELEMENT_prop (for proppatch)
type proppatchProps []Property type proppatchProps []Property
var xmlLangName = xml.Name{Space: "http://www.w3.org/XML/1998/namespace", Local: "lang"} var xmlLangName = ixml.Name{Space: "http://www.w3.org/XML/1998/namespace", Local: "lang"}
func xmlLang(s xml.StartElement, d string) string { func xmlLang(s ixml.StartElement, d string) string {
for _, attr := range s.Attr { for _, attr := range s.Attr {
if attr.Name == xmlLangName { if attr.Name == xmlLangName {
return attr.Value return attr.Value
...@@ -366,19 +366,19 @@ func xmlLang(s xml.StartElement, d string) string { ...@@ -366,19 +366,19 @@ func xmlLang(s xml.StartElement, d string) string {
type xmlValue []byte type xmlValue []byte
func (v *xmlValue) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (v *xmlValue) UnmarshalXML(d *ixml.Decoder, start ixml.StartElement) error {
// The XML value of a property can be arbitrary, mixed-content XML. // The XML value of a property can be arbitrary, mixed-content XML.
// To make sure that the unmarshalled value contains all required // To make sure that the unmarshalled value contains all required
// namespaces, we encode all the property value XML tokens into a // namespaces, we encode all the property value XML tokens into a
// buffer. This forces the encoder to redeclare any used namespaces. // buffer. This forces the encoder to redeclare any used namespaces.
var b bytes.Buffer var b bytes.Buffer
e := xml.NewEncoder(&b) e := ixml.NewEncoder(&b)
for { for {
t, err := next(d) t, err := next(d)
if err != nil { if err != nil {
return err return err
} }
if e, ok := t.(xml.EndElement); ok && e.Name == start.Name { if e, ok := t.(ixml.EndElement); ok && e.Name == start.Name {
break break
} }
if err = e.EncodeToken(t); err != nil { if err = e.EncodeToken(t); err != nil {
...@@ -401,7 +401,7 @@ func (v *xmlValue) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { ...@@ -401,7 +401,7 @@ func (v *xmlValue) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
// //
// UnmarshalXML returns an error if start does not contain any properties or if // UnmarshalXML returns an error if start does not contain any properties or if
// property values contain syntactically incorrect XML. // property values contain syntactically incorrect XML.
func (ps *proppatchProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func (ps *proppatchProps) UnmarshalXML(d *ixml.Decoder, start ixml.StartElement) error {
lang := xmlLang(start, "") lang := xmlLang(start, "")
for { for {
t, err := next(d) t, err := next(d)
...@@ -409,15 +409,15 @@ func (ps *proppatchProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) e ...@@ -409,15 +409,15 @@ func (ps *proppatchProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) e
return err return err
} }
switch elem := t.(type) { switch elem := t.(type) {
case xml.EndElement: case ixml.EndElement:
if len(*ps) == 0 { if len(*ps) == 0 {
return fmt.Errorf("%s must not be empty", start.Name.Local) return fmt.Errorf("%s must not be empty", start.Name.Local)
} }
return nil return nil
case xml.StartElement: case ixml.StartElement:
p := Property{ p := Property{
XMLName: t.(xml.StartElement).Name, XMLName: t.(ixml.StartElement).Name,
Lang: xmlLang(t.(xml.StartElement), lang), Lang: xmlLang(t.(ixml.StartElement), lang),
} }
err = d.DecodeElement(((*xmlValue)(&p.InnerXML)), &elem) err = d.DecodeElement(((*xmlValue)(&p.InnerXML)), &elem)
if err != nil { if err != nil {
...@@ -431,29 +431,29 @@ func (ps *proppatchProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) e ...@@ -431,29 +431,29 @@ func (ps *proppatchProps) UnmarshalXML(d *xml.Decoder, start xml.StartElement) e
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_set // http://www.webdav.org/specs/rfc4918.html#ELEMENT_set
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_remove // http://www.webdav.org/specs/rfc4918.html#ELEMENT_remove
type setRemove struct { type setRemove struct {
XMLName xml.Name XMLName ixml.Name
Lang string `xml:"xml:lang,attr,omitempty"` Lang string `xml:"xml:lang,attr,omitempty"`
Prop proppatchProps `xml:"DAV: prop"` Prop proppatchProps `xml:"DAV: prop"`
} }
// http://www.webdav.org/specs/rfc4918.html#ELEMENT_propertyupdate // http://www.webdav.org/specs/rfc4918.html#ELEMENT_propertyupdate
type propertyupdate struct { type propertyupdate struct {
XMLName xml.Name `xml:"DAV: propertyupdate"` XMLName ixml.Name `xml:"DAV: propertyupdate"`
Lang string `xml:"xml:lang,attr,omitempty"` Lang string `xml:"xml:lang,attr,omitempty"`
SetRemove []setRemove `xml:",any"` SetRemove []setRemove `xml:",any"`
} }
func readProppatch(r io.Reader) (patches []Proppatch, status int, err error) { func readProppatch(r io.Reader) (patches []Proppatch, status int, err error) {
var pu propertyupdate var pu propertyupdate
if err = xml.NewDecoder(r).Decode(&pu); err != nil { if err = ixml.NewDecoder(r).Decode(&pu); err != nil {
return nil, http.StatusBadRequest, err return nil, http.StatusBadRequest, err
} }
for _, op := range pu.SetRemove { for _, op := range pu.SetRemove {
remove := false remove := false
switch op.XMLName { switch op.XMLName {
case xml.Name{Space: "DAV:", Local: "set"}: case ixml.Name{Space: "DAV:", Local: "set"}:
// No-op. // No-op.
case xml.Name{Space: "DAV:", Local: "remove"}: case ixml.Name{Space: "DAV:", Local: "remove"}:
for _, p := range op.Prop { for _, p := range op.Prop {
if len(p.InnerXML) > 0 { if len(p.InnerXML) > 0 {
return nil, http.StatusBadRequest, errInvalidProppatch return nil, http.StatusBadRequest, errInvalidProppatch
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
"strings" "strings"
"testing" "testing"
"golang.org/x/net/webdav/internal/xml" ixml "golang.org/x/net/webdav/internal/xml"
) )
func TestReadLockInfo(t *testing.T) { func TestReadLockInfo(t *testing.T) {
...@@ -86,7 +86,7 @@ func TestReadLockInfo(t *testing.T) { ...@@ -86,7 +86,7 @@ func TestReadLockInfo(t *testing.T) {
" <D:owner>gopher</D:owner>\n" + " <D:owner>gopher</D:owner>\n" +
"</D:lockinfo>", "</D:lockinfo>",
lockInfo{ lockInfo{
XMLName: xml.Name{Space: "DAV:", Local: "lockinfo"}, XMLName: ixml.Name{Space: "DAV:", Local: "lockinfo"},
Exclusive: new(struct{}), Exclusive: new(struct{}),
Write: new(struct{}), Write: new(struct{}),
Owner: owner{ Owner: owner{
...@@ -105,7 +105,7 @@ func TestReadLockInfo(t *testing.T) { ...@@ -105,7 +105,7 @@ func TestReadLockInfo(t *testing.T) {
" </D:owner>\n" + " </D:owner>\n" +
"</D:lockinfo>", "</D:lockinfo>",
lockInfo{ lockInfo{
XMLName: xml.Name{Space: "DAV:", Local: "lockinfo"}, XMLName: ixml.Name{Space: "DAV:", Local: "lockinfo"},
Exclusive: new(struct{}), Exclusive: new(struct{}),
Write: new(struct{}), Write: new(struct{}),
Owner: owner{ Owner: owner{
...@@ -147,7 +147,7 @@ func TestReadPropfind(t *testing.T) { ...@@ -147,7 +147,7 @@ func TestReadPropfind(t *testing.T) {
" <A:propname/>\n" + " <A:propname/>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: xml.Name{Space: "DAV:", Local: "propfind"}, XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
Propname: new(struct{}), Propname: new(struct{}),
}, },
}, { }, {
...@@ -163,7 +163,7 @@ func TestReadPropfind(t *testing.T) { ...@@ -163,7 +163,7 @@ func TestReadPropfind(t *testing.T) {
" <A:allprop/>\n" + " <A:allprop/>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: xml.Name{Space: "DAV:", Local: "propfind"}, XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
Allprop: new(struct{}), Allprop: new(struct{}),
}, },
}, { }, {
...@@ -174,9 +174,9 @@ func TestReadPropfind(t *testing.T) { ...@@ -174,9 +174,9 @@ func TestReadPropfind(t *testing.T) {
" <A:include><A:displayname/></A:include>\n" + " <A:include><A:displayname/></A:include>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: xml.Name{Space: "DAV:", Local: "propfind"}, XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
Allprop: new(struct{}), Allprop: new(struct{}),
Include: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}}, Include: propfindProps{ixml.Name{Space: "DAV:", Local: "displayname"}},
}, },
}, { }, {
desc: "propfind: include followed by allprop", desc: "propfind: include followed by allprop",
...@@ -186,9 +186,9 @@ func TestReadPropfind(t *testing.T) { ...@@ -186,9 +186,9 @@ func TestReadPropfind(t *testing.T) {
" <A:allprop/>\n" + " <A:allprop/>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: xml.Name{Space: "DAV:", Local: "propfind"}, XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
Allprop: new(struct{}), Allprop: new(struct{}),
Include: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}}, Include: propfindProps{ixml.Name{Space: "DAV:", Local: "displayname"}},
}, },
}, { }, {
desc: "propfind: propfind", desc: "propfind: propfind",
...@@ -197,8 +197,8 @@ func TestReadPropfind(t *testing.T) { ...@@ -197,8 +197,8 @@ func TestReadPropfind(t *testing.T) {
" <A:prop><A:displayname/></A:prop>\n" + " <A:prop><A:displayname/></A:prop>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: xml.Name{Space: "DAV:", Local: "propfind"}, XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
Prop: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}}, Prop: propfindProps{ixml.Name{Space: "DAV:", Local: "displayname"}},
}, },
}, { }, {
desc: "propfind: prop with ignored comments", desc: "propfind: prop with ignored comments",
...@@ -210,8 +210,8 @@ func TestReadPropfind(t *testing.T) { ...@@ -210,8 +210,8 @@ func TestReadPropfind(t *testing.T) {
" </A:prop>\n" + " </A:prop>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: xml.Name{Space: "DAV:", Local: "propfind"}, XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
Prop: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}}, Prop: propfindProps{ixml.Name{Space: "DAV:", Local: "displayname"}},
}, },
}, { }, {
desc: "propfind: propfind with ignored whitespace", desc: "propfind: propfind with ignored whitespace",
...@@ -220,8 +220,8 @@ func TestReadPropfind(t *testing.T) { ...@@ -220,8 +220,8 @@ func TestReadPropfind(t *testing.T) {
" <A:prop> <A:displayname/></A:prop>\n" + " <A:prop> <A:displayname/></A:prop>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: xml.Name{Space: "DAV:", Local: "propfind"}, XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
Prop: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}}, Prop: propfindProps{ixml.Name{Space: "DAV:", Local: "displayname"}},
}, },
}, { }, {
desc: "propfind: propfind with ignored mixed-content", desc: "propfind: propfind with ignored mixed-content",
...@@ -230,8 +230,8 @@ func TestReadPropfind(t *testing.T) { ...@@ -230,8 +230,8 @@ func TestReadPropfind(t *testing.T) {
" <A:prop>foo<A:displayname/>bar</A:prop>\n" + " <A:prop>foo<A:displayname/>bar</A:prop>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: xml.Name{Space: "DAV:", Local: "propfind"}, XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
Prop: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}}, Prop: propfindProps{ixml.Name{Space: "DAV:", Local: "displayname"}},
}, },
}, { }, {
desc: "propfind: propname with ignored element (section A.4)", desc: "propfind: propname with ignored element (section A.4)",
...@@ -241,7 +241,7 @@ func TestReadPropfind(t *testing.T) { ...@@ -241,7 +241,7 @@ func TestReadPropfind(t *testing.T) {
" <E:leave-out xmlns:E='E:'>*boss*</E:leave-out>\n" + " <E:leave-out xmlns:E='E:'>*boss*</E:leave-out>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: xml.Name{Space: "DAV:", Local: "propfind"}, XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
Propname: new(struct{}), Propname: new(struct{}),
}, },
}, { }, {
...@@ -364,7 +364,7 @@ func TestMultistatusWriter(t *testing.T) { ...@@ -364,7 +364,7 @@ func TestMultistatusWriter(t *testing.T) {
Href: []string{"http://example.com/foo"}, Href: []string{"http://example.com/foo"},
Propstat: []propstat{{ Propstat: []propstat{{
Prop: []Property{{ Prop: []Property{{
XMLName: xml.Name{ XMLName: ixml.Name{
Space: "http://ns.example.com/", Space: "http://ns.example.com/",
Local: "Authors", Local: "Authors",
}, },
...@@ -372,7 +372,7 @@ func TestMultistatusWriter(t *testing.T) { ...@@ -372,7 +372,7 @@ func TestMultistatusWriter(t *testing.T) {
Status: "HTTP/1.1 424 Failed Dependency", Status: "HTTP/1.1 424 Failed Dependency",
}, { }, {
Prop: []Property{{ Prop: []Property{{
XMLName: xml.Name{ XMLName: ixml.Name{
Space: "http://ns.example.com/", Space: "http://ns.example.com/",
Local: "Copyright-Owner", Local: "Copyright-Owner",
}, },
...@@ -427,13 +427,13 @@ func TestMultistatusWriter(t *testing.T) { ...@@ -427,13 +427,13 @@ func TestMultistatusWriter(t *testing.T) {
Href: []string{"http://example.com/foo"}, Href: []string{"http://example.com/foo"},
Propstat: []propstat{{ Propstat: []propstat{{
Prop: []Property{{ Prop: []Property{{
XMLName: xml.Name{Space: "http://ns.example.com/boxschema/", Local: "bigbox"}, XMLName: ixml.Name{Space: "http://ns.example.com/boxschema/", Local: "bigbox"},
InnerXML: []byte(`` + InnerXML: []byte(`` +
`<BoxType xmlns="http://ns.example.com/boxschema/">` + `<BoxType xmlns="http://ns.example.com/boxschema/">` +
`Box type A` + `Box type A` +
`</BoxType>`), `</BoxType>`),
}, { }, {
XMLName: xml.Name{Space: "http://ns.example.com/boxschema/", Local: "author"}, XMLName: ixml.Name{Space: "http://ns.example.com/boxschema/", Local: "author"},
InnerXML: []byte(`` + InnerXML: []byte(`` +
`<Name xmlns="http://ns.example.com/boxschema/">` + `<Name xmlns="http://ns.example.com/boxschema/">` +
`J.J. Johnson` + `J.J. Johnson` +
...@@ -442,9 +442,9 @@ func TestMultistatusWriter(t *testing.T) { ...@@ -442,9 +442,9 @@ func TestMultistatusWriter(t *testing.T) {
Status: "HTTP/1.1 200 OK", Status: "HTTP/1.1 200 OK",
}, { }, {
Prop: []Property{{ Prop: []Property{{
XMLName: xml.Name{Space: "http://ns.example.com/boxschema/", Local: "DingALing"}, XMLName: ixml.Name{Space: "http://ns.example.com/boxschema/", Local: "DingALing"},
}, { }, {
XMLName: xml.Name{Space: "http://ns.example.com/boxschema/", Local: "Random"}, XMLName: ixml.Name{Space: "http://ns.example.com/boxschema/", Local: "Random"},
}}, }},
Status: "HTTP/1.1 403 Forbidden", Status: "HTTP/1.1 403 Forbidden",
ResponseDescription: "The user does not have access to the DingALing property.", ResponseDescription: "The user does not have access to the DingALing property.",
...@@ -494,7 +494,7 @@ func TestMultistatusWriter(t *testing.T) { ...@@ -494,7 +494,7 @@ func TestMultistatusWriter(t *testing.T) {
responses: []response{{ responses: []response{{
Propstat: []propstat{{ Propstat: []propstat{{
Prop: []Property{{ Prop: []Property{{
XMLName: xml.Name{ XMLName: ixml.Name{
Space: "http://example.com/", Space: "http://example.com/",
Local: "foo", Local: "foo",
}, },
...@@ -527,7 +527,7 @@ func TestMultistatusWriter(t *testing.T) { ...@@ -527,7 +527,7 @@ func TestMultistatusWriter(t *testing.T) {
Href: []string{"http://example.com/foo"}, Href: []string{"http://example.com/foo"},
Propstat: []propstat{{ Propstat: []propstat{{
Prop: []Property{{ Prop: []Property{{
XMLName: xml.Name{ XMLName: ixml.Name{
Space: "http://example.com/", Space: "http://example.com/",
Local: "foo", Local: "foo",
}, },
...@@ -548,7 +548,7 @@ func TestMultistatusWriter(t *testing.T) { ...@@ -548,7 +548,7 @@ func TestMultistatusWriter(t *testing.T) {
}, },
Propstat: []propstat{{ Propstat: []propstat{{
Prop: []Property{{ Prop: []Property{{
XMLName: xml.Name{ XMLName: ixml.Name{
Space: "http://example.com/", Space: "http://example.com/",
Local: "foo", Local: "foo",
}, },
...@@ -638,14 +638,14 @@ func TestReadProppatch(t *testing.T) { ...@@ -638,14 +638,14 @@ func TestReadProppatch(t *testing.T) {
`</D:propertyupdate>`, `</D:propertyupdate>`,
wantPP: []Proppatch{{ wantPP: []Proppatch{{
Props: []Property{{ Props: []Property{{
xml.Name{Space: "http://ns.example.com/z/", Local: "Authors"}, ixml.Name{Space: "http://ns.example.com/z/", Local: "Authors"},
"", "",
[]byte(`somevalue`), []byte(`somevalue`),
}}, }},
}, { }, {
Remove: true, Remove: true,
Props: []Property{{ Props: []Property{{
xml.Name{Space: "http://ns.example.com/z/", Local: "Copyright-Owner"}, ixml.Name{Space: "http://ns.example.com/z/", Local: "Copyright-Owner"},
"", "",
nil, nil,
}}, }},
...@@ -663,7 +663,7 @@ func TestReadProppatch(t *testing.T) { ...@@ -663,7 +663,7 @@ func TestReadProppatch(t *testing.T) {
`</D:propertyupdate>`, `</D:propertyupdate>`,
wantPP: []Proppatch{{ wantPP: []Proppatch{{
Props: []Property{{ Props: []Property{{
xml.Name{Space: "http://example.com/ns", Local: "foo"}, ixml.Name{Space: "http://example.com/ns", Local: "foo"},
"en", "en",
nil, nil,
}}, }},
...@@ -798,7 +798,7 @@ func TestUnmarshalXMLValue(t *testing.T) { ...@@ -798,7 +798,7 @@ func TestUnmarshalXMLValue(t *testing.T) {
var n xmlNormalizer var n xmlNormalizer
for _, tc := range testCases { for _, tc := range testCases {
d := xml.NewDecoder(strings.NewReader(tc.input)) d := ixml.NewDecoder(strings.NewReader(tc.input))
var v xmlValue var v xmlValue
if err := d.Decode(&v); err != nil { if err := d.Decode(&v); err != nil {
t.Errorf("%s: got error %v, want nil", tc.desc, err) t.Errorf("%s: got error %v, want nil", tc.desc, err)
...@@ -836,8 +836,8 @@ type xmlNormalizer struct { ...@@ -836,8 +836,8 @@ type xmlNormalizer struct {
// * Remove comments, if instructed to do so. // * Remove comments, if instructed to do so.
// //
func (n *xmlNormalizer) normalize(w io.Writer, r io.Reader) error { func (n *xmlNormalizer) normalize(w io.Writer, r io.Reader) error {
d := xml.NewDecoder(r) d := ixml.NewDecoder(r)
e := xml.NewEncoder(w) e := ixml.NewEncoder(w)
for { for {
t, err := d.Token() t, err := d.Token()
if err != nil { if err != nil {
...@@ -847,18 +847,18 @@ func (n *xmlNormalizer) normalize(w io.Writer, r io.Reader) error { ...@@ -847,18 +847,18 @@ func (n *xmlNormalizer) normalize(w io.Writer, r io.Reader) error {
return err return err
} }
switch val := t.(type) { switch val := t.(type) {
case xml.Directive, xml.ProcInst: case ixml.Directive, ixml.ProcInst:
continue continue
case xml.Comment: case ixml.Comment:
if n.omitComments { if n.omitComments {
continue continue
} }
case xml.CharData: case ixml.CharData:
if n.omitWhitespace && len(bytes.TrimSpace(val)) == 0 { if n.omitWhitespace && len(bytes.TrimSpace(val)) == 0 {
continue continue
} }
case xml.StartElement: case ixml.StartElement:
start, _ := xml.CopyToken(val).(xml.StartElement) start, _ := ixml.CopyToken(val).(ixml.StartElement)
attr := start.Attr[:0] attr := start.Attr[:0]
for _, a := range start.Attr { for _, a := range start.Attr {
if a.Name.Space == "xmlns" || a.Name.Local == "xmlns" { if a.Name.Space == "xmlns" || a.Name.Local == "xmlns" {
...@@ -893,7 +893,7 @@ func (n *xmlNormalizer) equalXML(a, b io.Reader) (bool, error) { ...@@ -893,7 +893,7 @@ func (n *xmlNormalizer) equalXML(a, b io.Reader) (bool, error) {
return normA == normB, nil return normA == normB, nil
} }
type byName []xml.Attr type byName []ixml.Attr
func (a byName) Len() int { return len(a) } func (a byName) Len() int { return len(a) }
func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
......
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