html: properly handle fragment foreign content breakout Change-Id: I8a97547c58fc74cb3c551a4a63f300a7254108f7 Reviewed-on: https://go-review.googlesource.com/c/net/+/781889 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Nicholas Husin <husin@google.com> Reviewed-by: Nicholas Husin <nsh@golang.org> Auto-Submit: Roland Shoemaker <roland@golang.org>
diff --git a/html/parse.go b/html/parse.go index b3d2a25..e584db4 100644 --- a/html/parse.go +++ b/html/parse.go
@@ -2174,7 +2174,7 @@ const whitespaceOrNUL = whitespace + "\x00" -// Section 12.2.6.5 +// Section 13.2.6.5 func parseForeignContent(p *parser) bool { switch p.tok.Type { case TextToken: @@ -2189,28 +2189,26 @@ Data: p.tok.Data, }) case StartTagToken: - if !p.fragment { - b := breakout[p.tok.Data] - if p.tok.DataAtom == a.Font { - loop: - for _, attr := range p.tok.Attr { - switch attr.Key { - case "color", "face", "size": - b = true - break loop - } + b := breakout[p.tok.Data] + if p.tok.DataAtom == a.Font { + loop: + for _, attr := range p.tok.Attr { + switch attr.Key { + case "color", "face", "size": + b = true + break loop } } - if b { - for i := len(p.oe) - 1; i >= 0; i-- { - n := p.oe[i] - if n.Namespace == "" || htmlIntegrationPoint(n) || mathMLTextIntegrationPoint(n) { - p.oe = p.oe[:i+1] - break - } + } + if b { + for i := len(p.oe) - 1; i >= 0; i-- { + n := p.oe[i] + if n.Namespace == "" || htmlIntegrationPoint(n) || mathMLTextIntegrationPoint(n) { + p.oe = p.oe[:i+1] + break } - return false } + return p.im(p) } current := p.adjustedCurrentNode() switch current.Namespace {
diff --git a/html/parse_test.go b/html/parse_test.go index 9d1fb51..c679279 100644 --- a/html/parse_test.go +++ b/html/parse_test.go
@@ -246,21 +246,6 @@ func TestParser(t *testing.T) { skipTests := map[string]bool{ - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/0": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/1": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/38": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/40": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/47": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/48": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/57": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/58": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/59": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/60": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/61": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/62": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/63": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/64": true, - "testdata/html5lib-tests/tree-construction/foreign-fragment.dat/65": true, "testdata/html5lib-tests/tree-construction/menuitem-element.dat/13": true, "testdata/html5lib-tests/tree-construction/tests1.dat/29": true, "testdata/html5lib-tests/tree-construction/tests1.dat/99": true,