]> Cypherpunks repositories - gostls13.git/commitdiff
html: handle end tags in strange places
authorAndrew Balholm <andybalholm@gmail.com>
Sat, 12 Nov 2011 01:23:30 +0000 (12:23 +1100)
committerNigel Tao <nigeltao@golang.org>
Sat, 12 Nov 2011 01:23:30 +0000 (12:23 +1100)
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

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

index e609cce12985d5f47898de31bb772f93fb1e1971..9dd5a4091c626c69fbc405bb4fc77a6b1e72a3fc 100644 (file)
@@ -352,30 +352,19 @@ func initialIM(p *parser) (insertionMode, bool) {
 
 // Section 11.2.5.4.2.
 func beforeHTMLIM(p *parser) (insertionMode, bool) {
-       var (
-               add     bool
-               attr    []Attribute
-               implied bool
-       )
        switch p.tok.Type {
-       case ErrorToken:
-               implied = true
-       case TextToken:
-               // TODO: distinguish whitespace text from others.
-               implied = true
        case StartTagToken:
                if p.tok.Data == "html" {
-                       add = true
-                       attr = p.tok.Attr
-               } else {
-                       implied = true
+                       p.addElement(p.tok.Data, p.tok.Attr)
+                       return beforeHeadIM, true
                }
        case EndTagToken:
                switch p.tok.Data {
                case "head", "body", "html", "br":
-                       implied = true
+                       // Drop down to creating an implied <html> tag.
                default:
                        // Ignore the token.
+                       return beforeHTMLIM, true
                }
        case CommentToken:
                p.doc.Add(&Node{
@@ -384,10 +373,9 @@ func beforeHTMLIM(p *parser) (insertionMode, bool) {
                })
                return beforeHTMLIM, true
        }
-       if add || implied {
-               p.addElement("html", attr)
-       }
-       return beforeHeadIM, !implied
+       // Create an implied <html> tag.
+       p.addElement("html", nil)
+       return beforeHeadIM, false
 }
 
 // Section 11.2.5.4.3.
@@ -691,6 +679,9 @@ func inBodyIM(p *parser) (insertionMode, bool) {
                        if p.popUntil(defaultScopeStopTags, p.tok.Data) {
                                p.clearActiveFormattingElements()
                        }
+               case "br":
+                       p.tok.Type = StartTagToken
+                       return inBodyIM, false
                default:
                        p.inBodyEndTagOther(p.tok.Data)
                }
@@ -1192,18 +1183,15 @@ func inSelectIM(p *parser) (insertionMode, bool) {
 func afterBodyIM(p *parser) (insertionMode, bool) {
        switch p.tok.Type {
        case ErrorToken:
-               // TODO.
-       case TextToken:
-               // TODO.
+               // Stop parsing.
+               return nil, true
        case StartTagToken:
-               // TODO.
+               if p.tok.Data == "html" {
+                       return useTheRulesFor(p, afterBodyIM, inBodyIM)
+               }
        case EndTagToken:
-               switch p.tok.Data {
-               case "html":
-                       // TODO: autoclose the stack of open elements.
+               if p.tok.Data == "html" {
                        return afterAfterBodyIM, true
-               default:
-                       // TODO.
                }
        case CommentToken:
                // The comment is attached to the <html> element.
@@ -1216,8 +1204,7 @@ func afterBodyIM(p *parser) (insertionMode, bool) {
                })
                return afterBodyIM, true
        }
-       // TODO: should this be "return inBodyIM, true"?
-       return afterBodyIM, true
+       return inBodyIM, false
 }
 
 // Section 11.2.5.4.19.
index d783ee32c925eac80fb02967b1afe2a3f1111ebc..13c50a99bc1e7d922e4021561d5c51d7c41c49e7 100644 (file)
@@ -133,7 +133,7 @@ func TestParser(t *testing.T) {
                n int
        }{
                // TODO(nigeltao): Process all the test cases from all the .dat files.
-               {"tests1.dat", 111},
+               {"tests1.dat", -1},
                {"tests2.dat", 0},
                {"tests3.dat", 0},
        }