Skip to content

Commit

Permalink
Revert "encoding/xml: fix reserved namespace check to be case-insensi…
Browse files Browse the repository at this point in the history
…tive"

This reverts CL 203417.

Reason for revert: This change changes uses of tags like "XMLSchema-instance" without any recourse.

For golang#35151
Fixes golang#39876

Change-Id: I4c85c8267a46b3748664b5078794dafffb42aa26
Reviewed-on: https://go-review.googlesource.com/c/go/+/240179
Run-TryBot: Ian Lance Taylor <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Emmanuel Odeke <[email protected]>
Reviewed-by: Andrew Bonventre <[email protected]>
  • Loading branch information
ianlancetaylor committed Jun 29, 2020
1 parent db85615 commit 2ca0f5a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
7 changes: 2 additions & 5 deletions src/encoding/xml/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,8 @@ func (p *printer) createAttrPrefix(url string) string {
if prefix == "" || !isName([]byte(prefix)) || strings.Contains(prefix, ":") {
prefix = "_"
}
// xmlanything is reserved and any variant of it regardless of
// case should be matched, so:
// (('X'|'x') ('M'|'m') ('L'|'l'))
// See Section 2.3 of https://www.w3.org/TR/REC-xml/
if len(prefix) >= 3 && strings.EqualFold(prefix[:3], "xml") {
if strings.HasPrefix(prefix, "xml") {
// xmlanything is reserved.
prefix = "_" + prefix
}
if p.attrNS[prefix] != "" {
Expand Down
24 changes: 0 additions & 24 deletions src/encoding/xml/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2283,30 +2283,6 @@ var encodeTokenTests = []struct {
}},
},
want: `<foo xmlns="space"><bar xmlns="space" xmlns:space="space" space:attr="value">`,
}, {
desc: "reserved namespace prefix -- all lower case",
toks: []Token{
StartElement{Name{"", "foo"}, []Attr{
{Name{"http://www.w3.org/2001/xmlSchema-instance", "nil"}, "true"},
}},
},
want: `<foo xmlns:_xmlSchema-instance="http://www.w3.org/2001/xmlSchema-instance" _xmlSchema-instance:nil="true">`,
}, {
desc: "reserved namespace prefix -- all upper case",
toks: []Token{
StartElement{Name{"", "foo"}, []Attr{
{Name{"http://www.w3.org/2001/XMLSchema-instance", "nil"}, "true"},
}},
},
want: `<foo xmlns:_XMLSchema-instance="http://www.w3.org/2001/XMLSchema-instance" _XMLSchema-instance:nil="true">`,
}, {
desc: "reserved namespace prefix -- all mixed case",
toks: []Token{
StartElement{Name{"", "foo"}, []Attr{
{Name{"http://www.w3.org/2001/XmLSchema-instance", "nil"}, "true"},
}},
},
want: `<foo xmlns:_XmLSchema-instance="http://www.w3.org/2001/XmLSchema-instance" _XmLSchema-instance:nil="true">`,
}}

func TestEncodeToken(t *testing.T) {
Expand Down

0 comments on commit 2ca0f5a

Please sign in to comment.