diff --git a/doc/go1.16.html b/doc/go1.16.html index b6df0487ca..1239217eed 100644 --- a/doc/go1.16.html +++ b/doc/go1.16.html @@ -302,6 +302,20 @@ Do not send CLs removing the interior tags from such phrases. +
+ The encoder has always taken care to avoid using namespace prefixes
+ beginning with xml
, which are reserved by the XML
+ specification.
+ Now, following the specification more closely, that check is
+ case-insensitive, so that prefixes beginning
+ with XML
, XmL
, and so on are also
+ avoided.
+
diff --git a/src/encoding/xml/marshal.go b/src/encoding/xml/marshal.go
index 0554b0d204..d8a04a95a2 100644
--- a/src/encoding/xml/marshal.go
+++ b/src/encoding/xml/marshal.go
@@ -345,8 +345,11 @@ func (p *printer) createAttrPrefix(url string) string {
if prefix == "" || !isName([]byte(prefix)) || strings.Contains(prefix, ":") {
prefix = "_"
}
- if strings.HasPrefix(prefix, "xml") {
- // xmlanything is reserved.
+ // 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") {
prefix = "_" + prefix
}
if p.attrNS[prefix] != "" {
diff --git a/src/encoding/xml/marshal_test.go b/src/encoding/xml/marshal_test.go
index 31309ef2ca..d2e5137afd 100644
--- a/src/encoding/xml/marshal_test.go
+++ b/src/encoding/xml/marshal_test.go
@@ -2283,6 +2283,30 @@ var encodeTokenTests = []struct {
}},
},
want: `