mirror of
https://github.com/golang/go
synced 2024-11-25 01:08:02 -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
|
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]
|
b[dst] = b[src]
|
||||||
return dst + 1, src + 1
|
return dst + 1, src + 1
|
||||||
}
|
}
|
||||||
|
@ -49,12 +49,24 @@ var unescapeTests = []unescapeTest{
|
|||||||
"Delta = Δ ",
|
"Delta = Δ ",
|
||||||
"Delta = Δ ",
|
"Delta = Δ ",
|
||||||
},
|
},
|
||||||
|
// Handle single-digit decimal numeric entities.
|
||||||
|
{
|
||||||
|
"singleDigitDecimalEntity",
|
||||||
|
"Tab = 	 = 	 ",
|
||||||
|
"Tab = \t = \t ",
|
||||||
|
},
|
||||||
// Handle hexadecimal numeric entities.
|
// Handle hexadecimal numeric entities.
|
||||||
{
|
{
|
||||||
"hexadecimalEntity",
|
"hexadecimalEntity",
|
||||||
"Lambda = λ = λ ",
|
"Lambda = λ = λ ",
|
||||||
"Lambda = λ = λ ",
|
"Lambda = λ = λ ",
|
||||||
},
|
},
|
||||||
|
// Handle single-digit hexadecimal numeric entities.
|
||||||
|
{
|
||||||
|
"singleDigitHexadecimalEntity",
|
||||||
|
"Tab = 	 = 	 ",
|
||||||
|
"Tab = \t = \t ",
|
||||||
|
},
|
||||||
// Handle numeric early termination.
|
// Handle numeric early termination.
|
||||||
{
|
{
|
||||||
"numericEnds",
|
"numericEnds",
|
||||||
@ -109,6 +121,7 @@ func TestUnescapeEscape(t *testing.T) {
|
|||||||
`"<&>"`,
|
`"<&>"`,
|
||||||
`3&5==1 && 0<1, "0<1", a+acute=á`,
|
`3&5==1 && 0<1, "0<1", a+acute=á`,
|
||||||
`The special characters are: <, >, &, ' and "`,
|
`The special characters are: <, >, &, ' and "`,
|
||||||
|
`	 	 	 	`,
|
||||||
}
|
}
|
||||||
for _, s := range ss {
|
for _, s := range ss {
|
||||||
if got := UnescapeString(EscapeString(s)); got != s {
|
if got := UnescapeString(EscapeString(s)); got != s {
|
||||||
|
Loading…
Reference in New Issue
Block a user