mirror of
https://github.com/golang/go
synced 2024-11-21 16:34:42 -07:00
html: handle single digit decimal numeric entities without semicolon
Fix handling of "	" and add tests for other single-digit cases. Fixes #66058 Updates #21563
This commit is contained in:
parent
f0d1195e13
commit
011e8f37f6
@ -104,7 +104,8 @@ func unescapeEntity(b []byte, dst, src int) (dst1, src1 int) {
|
||||
break
|
||||
}
|
||||
|
||||
if i <= 3 { // No characters matched.
|
||||
// We need to have at least "&#." or "&#x.".
|
||||
if (!hex && i < 3) || (hex && i < 4) {
|
||||
b[dst] = b[src]
|
||||
return dst + 1, src + 1
|
||||
}
|
||||
|
@ -49,12 +49,24 @@ var unescapeTests = []unescapeTest{
|
||||
"Delta = Δ ",
|
||||
"Delta = Δ ",
|
||||
},
|
||||
// Handle single-digit decimal numeric entities.
|
||||
{
|
||||
"singleDigitDecimalEntity",
|
||||
"Tab = 	 = 	 ",
|
||||
"Tab = \t = \t ",
|
||||
},
|
||||
// Handle hexadecimal numeric entities.
|
||||
{
|
||||
"hexadecimalEntity",
|
||||
"Lambda = λ = λ ",
|
||||
"Lambda = λ = λ ",
|
||||
},
|
||||
// Handle single-digit hexadecimal numeric entities.
|
||||
{
|
||||
"singleDigitHexadecimalEntity",
|
||||
"Tab = 	 = 	 ",
|
||||
"Tab = \t = \t ",
|
||||
},
|
||||
// Handle numeric early termination.
|
||||
{
|
||||
"numericEnds",
|
||||
@ -109,6 +121,7 @@ func TestUnescapeEscape(t *testing.T) {
|
||||
`"<&>"`,
|
||||
`3&5==1 && 0<1, "0<1", a+acute=á`,
|
||||
`The special characters are: <, >, &, ' and "`,
|
||||
`	 	 	 	`,
|
||||
}
|
||||
for _, s := range ss {
|
||||
if got := UnescapeString(EscapeString(s)); got != s {
|
||||
|
Loading…
Reference in New Issue
Block a user