]> Cypherpunks repositories - gostls13.git/commitdiff
html: properly close <tr> element when an new <tr> starts.
authorAndrew Balholm <andybalholm@gmail.com>
Fri, 4 Nov 2011 04:48:11 +0000 (15:48 +1100)
committerNigel Tao <nigeltao@golang.org>
Fri, 4 Nov 2011 04:48:11 +0000 (15:48 +1100)
Pass tests1.dat, test 87:
<table><tr><tr><td><td><span><th><span>X</table>

| <html>
|   <head>
|   <body>
|     <table>
|       <tbody>
|         <tr>
|         <tr>
|           <td>
|           <td>
|             <span>
|           <th>
|             <span>
|               "X"

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

src/pkg/html/parse.go
src/pkg/html/parse_test.go

index 0204b7c281cee8c0cab7b601969508b8e66bd863..811e2654731d60cee8980ea1ea787744e5de8013 100644 (file)
@@ -943,22 +943,27 @@ func inRowIM(p *parser) (insertionMode, bool) {
        case StartTagToken:
                switch p.tok.Data {
                case "td", "th":
-                       // TODO: clear the stack back to a table row context.
+                       p.clearStackToContext(tableRowContextStopTags)
                        p.addElement(p.tok.Data, p.tok.Attr)
                        p.afe = append(p.afe, &scopeMarker)
                        return inCellIM, true
+               case "caption", "col", "colgroup", "tbody", "tfoot", "thead", "tr":
+                       if p.popUntil(tableScopeStopTags, "tr") {
+                               return inTableBodyIM, false
+                       }
+                       // Ignore the token.
+                       return inRowIM, true
                default:
                        // TODO.
                }
        case EndTagToken:
                switch p.tok.Data {
                case "tr":
-                       if !p.elementInScope(tableScopeStopTags, "tr") {
-                               return inRowIM, true
+                       if p.popUntil(tableScopeStopTags, "tr") {
+                               return inTableBodyIM, true
                        }
-                       p.clearStackToContext(tableRowContextStopTags)
-                       p.oe.pop()
-                       return inTableBodyIM, true
+                       // Ignore the token.
+                       return inRowIM, true
                case "table":
                        if p.popUntil(tableScopeStopTags, "tr") {
                                return inTableBodyIM, false
index 8dc00ba484c4d849f2647ceaeb5015acbfe406f2..a6398e7a124379143d38280218fcf1c305da5525 100644 (file)
@@ -133,7 +133,7 @@ func TestParser(t *testing.T) {
                rc := make(chan io.Reader)
                go readDat(filename, rc)
                // TODO(nigeltao): Process all test cases, not just a subset.
-               for i := 0; i < 86; i++ {
+               for i := 0; i < 87; i++ {
                        // Parse the #data section.
                        b, err := ioutil.ReadAll(<-rc)
                        if err != nil {