html: handle equals sign before attribute

Apply the correct normalization when an equals sign appears before an
attribute name (e.g. '<tag =>' -> '<tag =="">'), per WHATWG 13.2.5.32.

Change-Id: Id21b428bd86117dd073c502767386bc718a3fb7b
Reviewed-on: https://go-review.googlesource.com/c/net/+/488695
Auto-Submit: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Reviewed-by: Nigel Tao (INACTIVE; USE @golang.org INSTEAD) <nigeltao@google.com>
This commit is contained in:
Roland Shoemaker 2023-04-25 10:17:09 -07:00 коммит произвёл Gopher Robot
Родитель f5464ddb68
Коммит 4050002696
2 изменённых файлов: 19 добавлений и 1 удалений

Просмотреть файл

@ -913,7 +913,14 @@ func (z *Tokenizer) readTagAttrKey() {
case ' ', '\n', '\r', '\t', '\f', '/':
z.pendingAttr[0].end = z.raw.end - 1
return
case '=', '>':
case '=':
if z.pendingAttr[0].start+1 == z.raw.end {
// WHATWG 13.2.5.32, if we see an equals sign before the attribute name
// begins, we treat it as a character in the attribute name and continue.
continue
}
fallthrough
case '>':
z.raw.end--
z.pendingAttr[0].end = z.raw.end
return

Просмотреть файл

@ -590,6 +590,17 @@ var tokenTests = []tokenTest{
`<p id=can't><p id=won't>`,
`<p id="can&#39;t">$<p id="won&#39;t">`,
},
// WHATWG 13.2.5.32 equals sign before attribute name state
{
"equals sign before attribute name",
`<p =>`,
`<p =="">`,
},
{
"equals sign before attribute name, extra cruft",
`<p =asd>`,
`<p =asd="">`,
},
}
func TestTokenizer(t *testing.T) {