Skip to content

Commit 828298c

Browse files
committed
encoding/xml: (*Decoder).nsname now strictly parses namespaces
1 parent 638f996 commit 828298c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/encoding/xml/xml.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -1211,17 +1211,18 @@ func (d *Decoder) nsname() (name Name, ok bool) {
12111211
if !ok {
12121212
return
12131213
}
1214-
if strings.Count(s, ":") > 1 {
1214+
n := strings.Count(s, ":")
1215+
if n == 0 { // No colons, no namespace. OK.
12151216
name.Local = s
1216-
} else if i := strings.Index(s, ":"); i < 1 || i > len(s)-2 {
1217+
} else if n > 1 { // More than one colon, not OK.
12171218
name.Local = s
1219+
return name, false
1220+
} else if i := strings.Index(s, ":"); i < 1 || i > len(s)-2 { // Leading or trailing colon, not OK.
1221+
name.Local = s
1222+
return name, false
12181223
} else {
12191224
name.Space = s[0:i]
1220-
if strings.Contains(s[i+1:], ":") {
1221-
return name, false
1222-
} else {
1223-
name.Local = s[i+1:]
1224-
}
1225+
name.Local = s[i+1:]
12251226
}
12261227
return name, true
12271228
}

0 commit comments

Comments
 (0)