Commit 3df05124 authored by Andrew Balholm's avatar Andrew Balholm Committed by Nigel Tao

html: handle end tags in strange places

Pass tests1.dat, test 111:
</strong></b></em></i></u></strike></s></blink></tt></pre></big></small></font></select></h1></h2></h3></h4></h5></h6></body></br></a></img></title></span></style></script></table></th></td></tr></frame></area></link></param></hr></input></col></base></meta></basefont></bgsound></embed></spacer></p></dd></dt></caption></colgroup></tbody></tfoot></thead></address></blockquote></center></dir></div></dl></fieldset></listing></menu></ol></ul></li></nobr></wbr></form></button></marquee></object></html></frameset></head></iframe></image></isindex></noembed></noframes></noscript></optgroup></option></plaintext></textarea>

| <html>
|   <head>
|   <body>
|     <br>
|     <p>

Also pass all the remaining tests in tests1.dat.

R=nigeltao
CC=golang-dev
https://golang.org/cl/5372066
parent e8188c16
...@@ -352,30 +352,19 @@ func initialIM(p *parser) (insertionMode, bool) { ...@@ -352,30 +352,19 @@ func initialIM(p *parser) (insertionMode, bool) {
// Section 11.2.5.4.2. // Section 11.2.5.4.2.
func beforeHTMLIM(p *parser) (insertionMode, bool) { func beforeHTMLIM(p *parser) (insertionMode, bool) {
var (
add bool
attr []Attribute
implied bool
)
switch p.tok.Type { switch p.tok.Type {
case ErrorToken:
implied = true
case TextToken:
// TODO: distinguish whitespace text from others.
implied = true
case StartTagToken: case StartTagToken:
if p.tok.Data == "html" { if p.tok.Data == "html" {
add = true p.addElement(p.tok.Data, p.tok.Attr)
attr = p.tok.Attr return beforeHeadIM, true
} else {
implied = true
} }
case EndTagToken: case EndTagToken:
switch p.tok.Data { switch p.tok.Data {
case "head", "body", "html", "br": case "head", "body", "html", "br":
implied = true // Drop down to creating an implied <html> tag.
default: default:
// Ignore the token. // Ignore the token.
return beforeHTMLIM, true
} }
case CommentToken: case CommentToken:
p.doc.Add(&Node{ p.doc.Add(&Node{
...@@ -384,10 +373,9 @@ func beforeHTMLIM(p *parser) (insertionMode, bool) { ...@@ -384,10 +373,9 @@ func beforeHTMLIM(p *parser) (insertionMode, bool) {
}) })
return beforeHTMLIM, true return beforeHTMLIM, true
} }
if add || implied { // Create an implied <html> tag.
p.addElement("html", attr) p.addElement("html", nil)
} return beforeHeadIM, false
return beforeHeadIM, !implied
} }
// Section 11.2.5.4.3. // Section 11.2.5.4.3.
...@@ -691,6 +679,9 @@ func inBodyIM(p *parser) (insertionMode, bool) { ...@@ -691,6 +679,9 @@ func inBodyIM(p *parser) (insertionMode, bool) {
if p.popUntil(defaultScopeStopTags, p.tok.Data) { if p.popUntil(defaultScopeStopTags, p.tok.Data) {
p.clearActiveFormattingElements() p.clearActiveFormattingElements()
} }
case "br":
p.tok.Type = StartTagToken
return inBodyIM, false
default: default:
p.inBodyEndTagOther(p.tok.Data) p.inBodyEndTagOther(p.tok.Data)
} }
...@@ -1192,18 +1183,15 @@ func inSelectIM(p *parser) (insertionMode, bool) { ...@@ -1192,18 +1183,15 @@ func inSelectIM(p *parser) (insertionMode, bool) {
func afterBodyIM(p *parser) (insertionMode, bool) { func afterBodyIM(p *parser) (insertionMode, bool) {
switch p.tok.Type { switch p.tok.Type {
case ErrorToken: case ErrorToken:
// TODO. // Stop parsing.
case TextToken: return nil, true
// TODO.
case StartTagToken: case StartTagToken:
// TODO. if p.tok.Data == "html" {
return useTheRulesFor(p, afterBodyIM, inBodyIM)
}
case EndTagToken: case EndTagToken:
switch p.tok.Data { if p.tok.Data == "html" {
case "html":
// TODO: autoclose the stack of open elements.
return afterAfterBodyIM, true return afterAfterBodyIM, true
default:
// TODO.
} }
case CommentToken: case CommentToken:
// The comment is attached to the <html> element. // The comment is attached to the <html> element.
...@@ -1216,8 +1204,7 @@ func afterBodyIM(p *parser) (insertionMode, bool) { ...@@ -1216,8 +1204,7 @@ func afterBodyIM(p *parser) (insertionMode, bool) {
}) })
return afterBodyIM, true return afterBodyIM, true
} }
// TODO: should this be "return inBodyIM, true"? return inBodyIM, false
return afterBodyIM, true
} }
// Section 11.2.5.4.19. // Section 11.2.5.4.19.
......
...@@ -133,7 +133,7 @@ func TestParser(t *testing.T) { ...@@ -133,7 +133,7 @@ func TestParser(t *testing.T) {
n int n int
}{ }{
// TODO(nigeltao): Process all the test cases from all the .dat files. // TODO(nigeltao): Process all the test cases from all the .dat files.
{"tests1.dat", 111}, {"tests1.dat", -1},
{"tests2.dat", 0}, {"tests2.dat", 0},
{"tests3.dat", 0}, {"tests3.dat", 0},
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment