Skip to content

Commit 8e66b04

Browse files
rolandshoemakergopherbot
authored andcommitted
html: use strings.EqualFold instead of lowering ourselves
Instead of using strings.ToLower and == to check case insensitive equality, just use strings.EqualFold, even when the strings are only ASCII. This prevents us unnecessarily lowering extremely long strings, which can be a somewhat expensive operation, even if we're only attempting to compare equality with five characters. Thanks to Guido Vranken for reporting this issue. Fixes golang/go#70906 Fixes CVE-2024-45338 Change-Id: I323b919f912d60dab6a87cadfdcac3e6b54cd128 Reviewed-on: https://go-review.googlesource.com/c/net/+/637536 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Gopher Robot <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Tatiana Bradley <[email protected]>
1 parent b935f7b commit 8e66b04

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

html/doctype.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func parseDoctype(s string) (n *Node, quirks bool) {
8787
}
8888
}
8989
if lastAttr := n.Attr[len(n.Attr)-1]; lastAttr.Key == "system" &&
90-
strings.ToLower(lastAttr.Val) == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd" {
90+
strings.EqualFold(lastAttr.Val, "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd") {
9191
quirks = true
9292
}
9393
}

html/foreign.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ func htmlIntegrationPoint(n *Node) bool {
4040
if n.Data == "annotation-xml" {
4141
for _, a := range n.Attr {
4242
if a.Key == "encoding" {
43-
val := strings.ToLower(a.Val)
44-
if val == "text/html" || val == "application/xhtml+xml" {
43+
if strings.EqualFold(a.Val, "text/html") || strings.EqualFold(a.Val, "application/xhtml+xml") {
4544
return true
4645
}
4746
}

html/parse.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ func inBodyIM(p *parser) bool {
10351035
if p.tok.DataAtom == a.Input {
10361036
for _, t := range p.tok.Attr {
10371037
if t.Key == "type" {
1038-
if strings.ToLower(t.Val) == "hidden" {
1038+
if strings.EqualFold(t.Val, "hidden") {
10391039
// Skip setting framesetOK = false
10401040
return true
10411041
}
@@ -1463,7 +1463,7 @@ func inTableIM(p *parser) bool {
14631463
return inHeadIM(p)
14641464
case a.Input:
14651465
for _, t := range p.tok.Attr {
1466-
if t.Key == "type" && strings.ToLower(t.Val) == "hidden" {
1466+
if t.Key == "type" && strings.EqualFold(t.Val, "hidden") {
14671467
p.addElement()
14681468
p.oe.pop()
14691469
return true

0 commit comments

Comments
 (0)