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 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 h1:R150MpwJIv1MpS0N/pc+NhTM8ajzvlmxlY5OYsrevXQ=
golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/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= 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) w.enc = xml.NewEncoder(w.w)
return w.enc.EncodeToken(xml.StartElement{ return w.enc.EncodeToken(xml.StartElement{
Name: xml.Name{ Name: xml.Name{
Space: "DAV:", Space: "",
Local: "multistatus", Local: "D:multistatus",
}, },
Attr: []xml.Attr{{ Attr: []xml.Attr{{
Name: xml.Name{Space: "xmlns", Local: "D"}, Name: xml.Name{Space: "", Local: "xmlns:D"},
Value: "DAV:", Value: "DAV:",
}}, }},
}) })
@ -314,7 +314,7 @@ func (w *multistatusWriter) close() error {
) )
} }
end = append(end, xml.EndElement{ end = append(end, xml.EndElement{
Name: xml.Name{Space: "DAV:", Local: "multistatus"}, Name: xml.Name{Space: "", Local: "D:multistatus"},
}) })
for _, t := range end { for _, t := range end {
err := w.enc.EncodeToken(t) err := w.enc.EncodeToken(t)

View File

@ -15,8 +15,6 @@ import (
"sort" "sort"
"strings" "strings"
"testing" "testing"
ixml "golang.org/x/net/webdav/internal/xml"
) )
func TestReadLockInfo(t *testing.T) { func TestReadLockInfo(t *testing.T) {
@ -87,7 +85,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: ixml.Name{Space: "DAV:", Local: "lockinfo"}, XMLName: xml.Name{Space: "DAV:", Local: "lockinfo"},
Exclusive: new(struct{}), Exclusive: new(struct{}),
Write: new(struct{}), Write: new(struct{}),
Owner: owner{ Owner: owner{
@ -106,7 +104,7 @@ func TestReadLockInfo(t *testing.T) {
" </D:owner>\n" + " </D:owner>\n" +
"</D:lockinfo>", "</D:lockinfo>",
lockInfo{ lockInfo{
XMLName: ixml.Name{Space: "DAV:", Local: "lockinfo"}, XMLName: xml.Name{Space: "DAV:", Local: "lockinfo"},
Exclusive: new(struct{}), Exclusive: new(struct{}),
Write: new(struct{}), Write: new(struct{}),
Owner: owner{ Owner: owner{
@ -148,7 +146,7 @@ func TestReadPropfind(t *testing.T) {
" <A:propname/>\n" + " <A:propname/>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"}, XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Propname: new(struct{}), Propname: new(struct{}),
}, },
}, { }, {
@ -164,7 +162,7 @@ func TestReadPropfind(t *testing.T) {
" <A:allprop/>\n" + " <A:allprop/>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"}, XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Allprop: new(struct{}), Allprop: new(struct{}),
}, },
}, { }, {
@ -175,7 +173,7 @@ 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: ixml.Name{Space: "DAV:", Local: "propfind"}, XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Allprop: new(struct{}), Allprop: new(struct{}),
Include: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}}, Include: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}},
}, },
@ -187,7 +185,7 @@ func TestReadPropfind(t *testing.T) {
" <A:allprop/>\n" + " <A:allprop/>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"}, XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Allprop: new(struct{}), Allprop: new(struct{}),
Include: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}}, 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:prop><A:displayname/></A:prop>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: 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"}}, Prop: propfindProps{xml.Name{Space: "DAV:", Local: "displayname"}},
}, },
}, { }, {
@ -211,7 +209,7 @@ func TestReadPropfind(t *testing.T) {
" </A:prop>\n" + " </A:prop>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: 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"}}, 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:prop> <A:displayname/></A:prop>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: 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"}}, 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:prop>foo<A:displayname/>bar</A:prop>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: 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"}}, 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" + " <E:leave-out xmlns:E='E:'>*boss*</E:leave-out>\n" +
"</A:propfind>", "</A:propfind>",
wantPF: propfind{ wantPF: propfind{
XMLName: ixml.Name{Space: "DAV:", Local: "propfind"}, XMLName: xml.Name{Space: "DAV:", Local: "propfind"},
Propname: new(struct{}), Propname: new(struct{}),
}, },
}, { }, {
@ -799,7 +797,7 @@ func TestUnmarshalXMLValue(t *testing.T) {
var n xmlNormalizer var n xmlNormalizer
for _, tc := range testCases { for _, tc := range testCases {
d := ixml.NewDecoder(strings.NewReader(tc.input)) d := xml.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)
@ -837,8 +835,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 := ixml.NewDecoder(r) d := xml.NewDecoder(r)
e := ixml.NewEncoder(w) e := xml.NewEncoder(w)
for { for {
t, err := d.Token() t, err := d.Token()
if err != nil { if err != nil {
@ -848,18 +846,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 ixml.Directive, ixml.ProcInst: case xml.Directive, xml.ProcInst:
continue continue
case ixml.Comment: case xml.Comment:
if n.omitComments { if n.omitComments {
continue continue
} }
case ixml.CharData: case xml.CharData:
if n.omitWhitespace && len(bytes.TrimSpace(val)) == 0 { if n.omitWhitespace && len(bytes.TrimSpace(val)) == 0 {
continue continue
} }
case ixml.StartElement: case xml.StartElement:
start, _ := ixml.CopyToken(val).(ixml.StartElement) start, _ := xml.CopyToken(val).(xml.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" {
@ -894,7 +892,7 @@ func (n *xmlNormalizer) equalXML(a, b io.Reader) (bool, error) {
return normA == normB, nil return normA == normB, nil
} }
type byName []ixml.Attr type byName []xml.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] }