diff --git a/src/pkg/exp/html/parse.go b/src/pkg/exp/html/parse.go index afdfc9989c..6b1f40cb8e 100644 --- a/src/pkg/exp/html/parse.go +++ b/src/pkg/exp/html/parse.go @@ -208,7 +208,15 @@ loop: // addChild adds a child node n to the top element, and pushes n onto the stack // of open elements if it is an element node. func (p *parser) addChild(n *Node) { + fp := false if p.fosterParenting { + switch p.top().DataAtom { + case a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr: + fp = true + } + } + + if fp { p.fosterParent(n) } else { p.top().Add(n) @@ -222,7 +230,6 @@ func (p *parser) addChild(n *Node) { // fosterParent adds a child node according to the foster parenting rules. // Section 12.2.5.3, "foster parenting". func (p *parser) fosterParent(n *Node) { - p.fosterParenting = false var table, parent *Node var i int for i = len(p.oe) - 1; i >= 0; i-- { @@ -1308,11 +1315,8 @@ func inTableIM(p *parser) bool { return true } - switch p.top().DataAtom { - case a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr: - p.fosterParenting = true - defer func() { p.fosterParenting = false }() - } + p.fosterParenting = true + defer func() { p.fosterParenting = false }() return inBodyIM(p) } diff --git a/src/pkg/exp/html/parse_test.go b/src/pkg/exp/html/parse_test.go index e3c69b6f5b..e159b492f5 100644 --- a/src/pkg/exp/html/parse_test.go +++ b/src/pkg/exp/html/parse_test.go @@ -389,6 +389,8 @@ var renderTestBlacklist = map[string]bool{ `aba
First paragraph. Second paragrap
PASS "\n
`: true,
+ // A similar reparenting situation involving `: true,
diff --git a/src/pkg/exp/html/testlogs/tests26.dat.log b/src/pkg/exp/html/testlogs/tests26.dat.log
index fa97b44cd1..8f4d545abb 100644
--- a/src/pkg/exp/html/testlogs/tests26.dat.log
+++ b/src/pkg/exp/html/testlogs/tests26.dat.log
@@ -1,6 +1,6 @@
PASS " \n
\n"
PASS "\n