]> Cypherpunks repositories - gostls13.git/commitdiff
exp/html: adjust inTableBodyIM to match spec
authorAndrew Balholm <andybalholm@gmail.com>
Thu, 26 Apr 2012 01:48:35 +0000 (11:48 +1000)
committerNigel Tao <nigeltao@golang.org>
Thu, 26 Apr 2012 01:48:35 +0000 (11:48 +1000)
Clean up flow of control.

Handle </tbody>, </tfoot>, and </thead>.

Pass 5 additional tests.

R=nigeltao
CC=golang-dev
https://golang.org/cl/6117057

src/pkg/exp/html/parse.go
src/pkg/exp/html/testlogs/tests_innerHTML_1.dat.log

index 08f029c63eb47ea16f168fb8619a1b137f79171a..ba1ff0b447387ebe66d7fe60ba1e513262b48350 100644 (file)
@@ -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
+                       p.parseImpliedToken(StartTagToken, "tr", nil)
+                       return false
                case "caption", "col", "colgroup", "tbody", "tfoot", "thead":
-                       if !p.popUntil(tableScope, "tbody", "thead", "tfoot") {
-                               // Ignore the token.
-                               return true
+                       if p.popUntil(tableScope, "tbody", "thead", "tfoot") {
+                               p.im = inTableIM
+                               return false
                        }
-                       p.im = inTableIM
-                       return false
-               default:
-                       // TODO.
+                       // 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)
 }
 
index 5e50d799a640dc49272d6b95c3af62655d8e6c42..95f9f70000c04fc76d3d1caab23b359e816a7d84 100644 (file)
@@ -43,11 +43,11 @@ PASS "<tbody><a>"
 PASS "<tfoot><a>"
 PASS "<thead><a>"
 PASS "</table><a>"
-FAIL "<a><tr>"
-FAIL "<a><td>"
-FAIL "<a><td>"
-FAIL "<a><td>"
-FAIL "<td><table><tbody><a><tr>"
+PASS "<a><tr>"
+PASS "<a><td>"
+PASS "<a><td>"
+PASS "<a><td>"
+PASS "<td><table><tbody><a><tr>"
 PASS "</tr><td>"
 PASS "<td><table><a><tr></tr><tr>"
 PASS "<caption><td>"