1
0
mirror of https://github.com/golang/go synced 2024-11-22 06:24:38 -07:00

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
https://golang.org/cl/5343041
This commit is contained in:
Andrew Balholm 2011-11-04 15:48:11 +11:00 committed by Nigel Tao
parent 0865c57f25
commit 632a2c59b1
2 changed files with 12 additions and 7 deletions

View File

@ -943,22 +943,27 @@ func inRowIM(p *parser) (insertionMode, bool) {
case StartTagToken: case StartTagToken:
switch p.tok.Data { switch p.tok.Data {
case "td", "th": 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.addElement(p.tok.Data, p.tok.Attr)
p.afe = append(p.afe, &scopeMarker) p.afe = append(p.afe, &scopeMarker)
return inCellIM, true 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: default:
// TODO. // TODO.
} }
case EndTagToken: case EndTagToken:
switch p.tok.Data { switch p.tok.Data {
case "tr": case "tr":
if !p.elementInScope(tableScopeStopTags, "tr") { if p.popUntil(tableScopeStopTags, "tr") {
return inRowIM, true
}
p.clearStackToContext(tableRowContextStopTags)
p.oe.pop()
return inTableBodyIM, true return inTableBodyIM, true
}
// Ignore the token.
return inRowIM, true
case "table": case "table":
if p.popUntil(tableScopeStopTags, "tr") { if p.popUntil(tableScopeStopTags, "tr") {
return inTableBodyIM, false return inTableBodyIM, false

View File

@ -133,7 +133,7 @@ func TestParser(t *testing.T) {
rc := make(chan io.Reader) rc := make(chan io.Reader)
go readDat(filename, rc) go readDat(filename, rc)
// TODO(nigeltao): Process all test cases, not just a subset. // 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. // Parse the #data section.
b, err := ioutil.ReadAll(<-rc) b, err := ioutil.ReadAll(<-rc)
if err != nil { if err != nil {