diff options
author | Andrew Balholm <andybalholm@gmail.com> | 2011-11-04 15:48:11 +1100 |
---|---|---|
committer | Andrew Balholm <andybalholm@gmail.com> | 2011-11-04 15:48:11 +1100 |
commit | 37e4aeaf1b6cdce1664bd98611e48ff0466a36a6 (patch) | |
tree | aaab664261662a40af271cc047b6527efc284b78 | |
parent | 7c548bbfae938bc0cccabb1b28500ee44451443a (diff) | |
download | go-37e4aeaf1b6cdce1664bd98611e48ff0466a36a6.tar.gz |
html: properly close <tr> element when an new <tr> starts.
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
http://codereview.appspot.com/5343041
Committer: Nigel Tao <nigeltao@golang.org>
-rw-r--r-- | src/pkg/html/parse.go | 17 | ||||
-rw-r--r-- | src/pkg/html/parse_test.go | 2 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/pkg/html/parse.go b/src/pkg/html/parse.go index 0204b7c28..811e26547 100644 --- a/src/pkg/html/parse.go +++ b/src/pkg/html/parse.go @@ -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 diff --git a/src/pkg/html/parse_test.go b/src/pkg/html/parse_test.go index 8dc00ba48..a6398e7a1 100644 --- a/src/pkg/html/parse_test.go +++ b/src/pkg/html/parse_test.go @@ -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 { |