From d26f9f9a57f3fab6a695bec0d84433c2c50f8bbf Mon Sep 17 00:00:00 2001 From: Kunpei Sakai Date: Tue, 25 Sep 2018 22:55:50 +0900 Subject: [PATCH] html: update inSelectIM and inSelectInTableIM for the latest spec Fixes golang/go#27842 Change-Id: I06eb3c0c18be3566bd30a29fca5f3f7e6791d2cc Reviewed-on: https://go-review.googlesource.com/c/137275 Run-TryBot: Kunpei Sakai TryBot-Result: Gobot Gobot Reviewed-by: Nigel Tao --- html/parse.go | 28 ++++++++++++++++++++++------ html/parse_test.go | 3 ++- html/testdata/go/select.dat | 12 ++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 html/testdata/go/select.dat diff --git a/html/parse.go b/html/parse.go index 64a57937..488e8d3c 100644 --- a/html/parse.go +++ b/html/parse.go @@ -1719,8 +1719,12 @@ func inSelectIM(p *parser) bool { } p.addElement() case a.Select: - p.tok.Type = EndTagToken - return false + if p.popUntil(selectScope, a.Select) { + p.resetInsertionMode() + } else { + // Ignore the token. + return true + } case a.Input, a.Keygen, a.Textarea: if p.elementInScope(selectScope, a.Select) { p.parseImpliedToken(EndTagToken, a.Select, a.Select.String()) @@ -1750,6 +1754,9 @@ func inSelectIM(p *parser) bool { case a.Select: if p.popUntil(selectScope, a.Select) { p.resetInsertionMode() + } else { + // Ignore the token. + return true } case a.Template: return inHeadIM(p) @@ -1775,13 +1782,22 @@ func inSelectInTableIM(p *parser) bool { case StartTagToken, EndTagToken: switch p.tok.DataAtom { case a.Caption, a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr, a.Td, a.Th: - if p.tok.Type == StartTagToken || p.elementInScope(tableScope, p.tok.DataAtom) { - p.parseImpliedToken(EndTagToken, a.Select, a.Select.String()) - return false - } else { + if p.tok.Type == EndTagToken && !p.elementInScope(tableScope, p.tok.DataAtom) { // Ignore the token. return true } + // This is like p.popUntil(selectScope, a.Select), but it also + // matches , not just