Skip to content

Commit 011e8f3

Browse files
html: handle single digit decimal numeric entities without semicolon
Fix handling of "&#9" and add tests for other single-digit cases. Fixes #66058 Updates #21563
1 parent f0d1195 commit 011e8f3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/html/escape.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ func unescapeEntity(b []byte, dst, src int) (dst1, src1 int) {
104104
break
105105
}
106106

107-
if i <= 3 { // No characters matched.
107+
// We need to have at least "&#." or "&#x.".
108+
if (!hex && i < 3) || (hex && i < 4) {
108109
b[dst] = b[src]
109110
return dst + 1, src + 1
110111
}

src/html/escape_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,24 @@ var unescapeTests = []unescapeTest{
4949
"Delta = &#916; ",
5050
"Delta = Δ ",
5151
},
52+
// Handle single-digit decimal numeric entities.
53+
{
54+
"singleDigitDecimalEntity",
55+
"Tab = &#9; = &#9 ",
56+
"Tab = \t = \t ",
57+
},
5258
// Handle hexadecimal numeric entities.
5359
{
5460
"hexadecimalEntity",
5561
"Lambda = &#x3bb; = &#X3Bb ",
5662
"Lambda = λ = λ ",
5763
},
64+
// Handle single-digit hexadecimal numeric entities.
65+
{
66+
"singleDigitHexadecimalEntity",
67+
"Tab = &#x9; = &#x9 ",
68+
"Tab = \t = \t ",
69+
},
5870
// Handle numeric early termination.
5971
{
6072
"numericEnds",
@@ -109,6 +121,7 @@ func TestUnescapeEscape(t *testing.T) {
109121
`&quot;&lt;&amp;&gt;&quot;`,
110122
`3&5==1 && 0<1, "0&lt;1", a+acute=&aacute;`,
111123
`The special characters are: <, >, &, ' and "`,
124+
`&#9; &#9 &#x9; &#x9`,
112125
}
113126
for _, s := range ss {
114127
if got := UnescapeString(EscapeString(s)); got != s {

0 commit comments

Comments
 (0)