From a09e9811dc4db3c9205079a2eef21ffc7d7b5274 Mon Sep 17 00:00:00 2001 From: Andrew Balholm Date: Thu, 26 Apr 2012 11:48:35 +1000 Subject: [PATCH] exp/html: adjust inTableBodyIM to match spec Clean up flow of control. Handle , , and . Pass 5 additional tests. R=nigeltao CC=golang-dev https://golang.org/cl/6117057 --- src/pkg/exp/html/parse.go | 67 ++++++++++--------- .../html/testlogs/tests_innerHTML_1.dat.log | 10 +-- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/pkg/exp/html/parse.go b/src/pkg/exp/html/parse.go index 08f029c63e..ba1ff0b447 100644 --- a/src/pkg/exp/html/parse.go +++ b/src/pkg/exp/html/parse.go @@ -68,6 +68,7 @@ const ( buttonScope tableScope tableRowScope + tableBodyScope ) // popUntil pops the stack of open elements at the highest element whose tag @@ -160,6 +161,11 @@ func (p *parser) clearStackToContext(s scope) { p.oe = p.oe[:i+1] return } + case tableBodyScope: + if tag == "html" || tag == "tbody" || tag == "tfoot" || tag == "thead" { + p.oe = p.oe[:i+1] + return + } default: panic("unreachable") } @@ -1290,6 +1296,16 @@ func inCaptionIM(p *parser) bool { // Section 12.2.5.4.12. func inColumnGroupIM(p *parser) bool { switch p.tok.Type { + case TextToken: + s := strings.TrimLeft(p.tok.Data, whitespace) + if len(s) < len(p.tok.Data) { + // Add the initial whitespace to the current node. + p.addText(p.tok.Data[:len(p.tok.Data)-len(s)]) + if s == "" { + return true + } + p.tok.Data = s + } case CommentToken: p.addChild(&Node{ Type: CommentNode, @@ -1332,40 +1348,34 @@ func inColumnGroupIM(p *parser) bool { // Section 12.2.5.4.13. func inTableBodyIM(p *parser) bool { - var ( - add bool - data string - attr []Attribute - consumed bool - ) switch p.tok.Type { - case ErrorToken: - // TODO. - case TextToken: - // TODO. case StartTagToken: switch p.tok.Data { case "tr": - add = true - data = p.tok.Data - attr = p.tok.Attr - consumed = true + p.clearStackToContext(tableBodyScope) + p.addElement(p.tok.Data, p.tok.Attr) + p.im = inRowIM + return true case "td", "th": - add = true - data = "tr" - consumed = false - case "caption", "col", "colgroup", "tbody", "tfoot", "thead": - if !p.popUntil(tableScope, "tbody", "thead", "tfoot") { - // Ignore the token. - return true - } - p.im = inTableIM + p.parseImpliedToken(StartTagToken, "tr", nil) return false - default: - // TODO. + case "caption", "col", "colgroup", "tbody", "tfoot", "thead": + if p.popUntil(tableScope, "tbody", "thead", "tfoot") { + p.im = inTableIM + return false + } + // Ignore the token. + return true } case EndTagToken: switch p.tok.Data { + case "tbody", "tfoot", "thead": + if p.elementInScope(tableScope, p.tok.Data) { + p.clearStackToContext(tableBodyScope) + p.oe.pop() + p.im = inTableIM + } + return true case "table": if p.popUntil(tableScope, "tbody", "thead", "tfoot") { p.im = inTableIM @@ -1384,12 +1394,7 @@ func inTableBodyIM(p *parser) bool { }) return true } - if add { - // TODO: clear the stack back to a table body context. - p.addElement(data, attr) - p.im = inRowIM - return consumed - } + return inTableIM(p) } diff --git a/src/pkg/exp/html/testlogs/tests_innerHTML_1.dat.log b/src/pkg/exp/html/testlogs/tests_innerHTML_1.dat.log index 5e50d799a6..95f9f70000 100644 --- a/src/pkg/exp/html/testlogs/tests_innerHTML_1.dat.log +++ b/src/pkg/exp/html/testlogs/tests_innerHTML_1.dat.log @@ -43,11 +43,11 @@ PASS "" PASS "" PASS "" PASS "" -FAIL "" -FAIL "" -FAIL "" -FAIL "" -FAIL "" +PASS "" +PASS "
" +PASS "" +PASS "" +PASS "" PASS "
" PASS "" PASS "
"