switch to official xml package

This commit is contained in:
Newnius 2021-10-02 04:30:39 -04:00
parent 9e965d6281
commit 8497c9375c
4 changed files with 27 additions and 27 deletions

2
go.mod
View File

@ -2,4 +2,4 @@ module noahcloud
go 1.16
require golang.org/x/net v0.0.0-20210917221730-978cfadd31cf // indirect
require golang.org/x/net v0.0.0-20210924151903-3ad01bbaa167 // indirect

2
go.sum
View File

@ -1,5 +1,7 @@
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf h1:R150MpwJIv1MpS0N/pc+NhTM8ajzvlmxlY5OYsrevXQ=
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210924151903-3ad01bbaa167 h1:eDd+TJqbgfXruGQ5sJRU7tEtp/58OAx4+Ayjxg4SM+4=
golang.org/x/net v0.0.0-20210924151903-3ad01bbaa167/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

View File

@ -286,11 +286,11 @@ func (w *multistatusWriter) writeHeader() error {
w.enc = xml.NewEncoder(w.w)
return w.enc.EncodeToken(xml.StartElement{
Name: xml.Name{
Space: "DAV:",
Local: "multistatus",
Space: "",
Local: "D:multistatus",
},
Attr: []xml.Attr{{
Name: xml.Name{Space: "xmlns", Local: "D"},
Name: xml.Name{Space: "", Local: "xmlns:D"},
Value: "DAV:",
}},
})
@ -314,7 +314,7 @@ func (w *multistatusWriter) close() error {
)
}
end = append(end, xml.EndElement{
Name: xml.Name{Space: "DAV:", Local: "multistatus"},
Name: xml.Name{Space: "", Local: "D:multistatus"},
})
for _, t := range end {
err := w.enc.EncodeToken(t)

View File

@ -15,8 +15,6 @@ import (
"sort"
"strings"
"testing"
ixml "golang.org/x/net/webdav/internal/xml"
)
func TestReadLockInfo(t *testing.T) {
@ -87,7 +85,7 @@ func TestReadLockInfo(t *testing.T) {
" <D:owner>gopher</D:owner>\n" +
"</D:lockinfo>",
lockInfo{
XMLName: ixml.Name{Space: "DAV:", Local: "lockinfo"},
XMLName: xml.Name{Space: "DAV:", Local: "lockinfo"},
Exclusive: new(struct{}),
Write: new(struct{}),
Owner: owner{
@ -106,7 +104,7 @@ func TestReadLockInfo(t *testing.T) {
" </D:owner>\n" +
"</D:lockinfo>",
lockInfo{
XMLName: ixml.Name{Space: "DAV:", Local: "lockinfo"},
XMLName: xml.Name{Space: "DAV:", Local: "lockinfo"},
Exclusive: new(struct{}),
Write: new(struct{}),
Owner: owner{
@ -148,7 +146,7 @@ func TestReadPropfind(t *testing.T) {
" <A:propname/>\n" +
"</A:propfind>",
wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Propname: new(struct{}),
},
}, {
@ -164,7 +162,7 @@ func TestReadPropfind(t *testing.T) {
" <A:allprop/>\n" +
"</A:propfind>",
wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Allprop: new(struct{}),
},
}, {
@ -175,7 +173,7 @@ func TestReadPropfind(t *testing.T) {
" <A:include><A:displayname/></A:include>\n" +
"</A:propfind>",
wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Allprop: new(struct{}),
Include: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}},
},
@ -187,7 +185,7 @@ func TestReadPropfind(t *testing.T) {
" <A:allprop/>\n" +
"</A:propfind>",
wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Allprop: new(struct{}),
Include: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}},
},
@ -198,7 +196,7 @@ func TestReadPropfind(t *testing.T) {
" <A:prop><A:displayname/></A:prop>\n" +
"</A:propfind>",
wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Prop: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}},
},
}, {
@ -211,7 +209,7 @@ func TestReadPropfind(t *testing.T) {
" </A:prop>\n" +
"</A:propfind>",
wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Prop: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}},
},
}, {
@ -221,7 +219,7 @@ func TestReadPropfind(t *testing.T) {
" <A:prop> <A:displayname/></A:prop>\n" +
"</A:propfind>",
wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Prop: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}},
},
}, {
@ -231,7 +229,7 @@ func TestReadPropfind(t *testing.T) {
" <A:prop>foo<A:displayname/>bar</A:prop>\n" +
"</A:propfind>",
wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Prop: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}},
},
}, {
@ -242,7 +240,7 @@ func TestReadPropfind(t *testing.T) {
" <E:leave-out xmlns:E='E:'>*boss*</E:leave-out>\n" +
"</A:propfind>",
wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"},
XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Propname: new(struct{}),
},
}, {
@ -799,7 +797,7 @@ func TestUnmarshalXMLValue(t *testing.T) {
var n xmlNormalizer
for _, tc := range testCases {
d := ixml.NewDecoder(strings.NewReader(tc.input))
d := xml.NewDecoder(strings.NewReader(tc.input))
var v xmlValue
if err := d.Decode(&v); err != nil {
t.Errorf("%s: got error %v, want nil", tc.desc, err)
@ -837,8 +835,8 @@ type xmlNormalizer struct {
// * Remove comments, if instructed to do so.
//
func (n *xmlNormalizer) normalize(w io.Writer, r io.Reader) error {
d := ixml.NewDecoder(r)
e := ixml.NewEncoder(w)
d := xml.NewDecoder(r)
e := xml.NewEncoder(w)
for {
t, err := d.Token()
if err != nil {
@ -848,18 +846,18 @@ func (n *xmlNormalizer) normalize(w io.Writer, r io.Reader) error {
return err
}
switch val := t.(type) {
case ixml.Directive, ixml.ProcInst:
case xml.Directive, xml.ProcInst:
continue
case ixml.Comment:
case xml.Comment:
if n.omitComments {
continue
}
case ixml.CharData:
case xml.CharData:
if n.omitWhitespace && len(bytes.TrimSpace(val)) == 0 {
continue
}
case ixml.StartElement:
start, _ := ixml.CopyToken(val).(ixml.StartElement)
case xml.StartElement:
start, _ := xml.CopyToken(val).(xml.StartElement)
attr := start.Attr[:0]
for _, a := range start.Attr {
if a.Name.Space == "xmlns" || a.Name.Local == "xmlns" {
@ -894,7 +892,7 @@ func (n *xmlNormalizer) equalXML(a, b io.Reader) (bool, error) {
return normA == normB, nil
}
type byName []ixml.Attr
type byName []xml.Attr
func (a byName) Len() int { return len(a) }
func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }