Commit fca45719 authored by Andrew Balholm's avatar Andrew Balholm Committed by Nigel Tao

exp/html: foster-parent text correctly

If a table contained whitespace, text nodes would not get foster parented
correctly.

Pass 1 additional test.

R=nigeltao
CC=golang-dev
https://golang.org/cl/6459054
parent 5f7bec69
......@@ -208,15 +208,7 @@ 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 {
if p.shouldFosterParent() {
p.fosterParent(n)
} else {
p.top().Add(n)
......@@ -227,6 +219,18 @@ func (p *parser) addChild(n *Node) {
}
}
// shouldFosterParent returns whether the next node to be added should be
// foster parented.
func (p *parser) shouldFosterParent() bool {
if p.fosterParenting {
switch p.top().DataAtom {
case a.Table, a.Tbody, a.Tfoot, a.Thead, a.Tr:
return true
}
}
return false
}
// fosterParent adds a child node according to the foster parenting rules.
// Section 12.2.5.3, "foster parenting".
func (p *parser) fosterParent(n *Node) {
......@@ -277,7 +281,15 @@ func (p *parser) addText(text string) {
if text == "" {
return
}
// TODO: distinguish whitespace text from others.
if p.shouldFosterParent() {
p.fosterParent(&Node{
Type: TextNode,
Data: text,
})
return
}
t := p.top()
if i := len(t.Child); i > 0 && t.Child[i-1].Type == TextNode {
t.Child[i-1].Data += text
......
......@@ -26,5 +26,5 @@ PASS "<div><p>a</x> b"
PASS "<table><tr><td><code></code> </table>"
PASS "<table><b><tr><td>aaa</td></tr>bbb</table>ccc"
PASS "A<table><tr> B</tr> B</table>"
FAIL "A<table><tr> B</tr> </em>C</table>"
PASS "A<table><tr> B</tr> </em>C</table>"
PASS "<select><keygen>"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment