]> Cypherpunks repositories - gostls13.git/commitdiff
exp/html: start making inBodyIM match the spec
authorAndrew Balholm <andybalholm@gmail.com>
Fri, 20 Apr 2012 05:48:13 +0000 (15:48 +1000)
committerNigel Tao <nigeltao@golang.org>
Fri, 20 Apr 2012 05:48:13 +0000 (15:48 +1000)
Reorder some start tags.

Improve handling of </body>.
Handle </html>.

Pass 2 additional tests (by handling </html>).

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

src/pkg/exp/html/parse.go
src/pkg/exp/html/testlogs/tests15.dat.log
src/pkg/exp/html/testlogs/webkit01.dat.log

index b5ee425747bb4793aad0004b26fd5b8d7203e8e9..780b47a27a56959580f9adb8e03e9c34e4850150 100644 (file)
@@ -640,6 +640,29 @@ func inBodyIM(p *parser) bool {
                switch p.tok.Data {
                case "html":
                        copyAttributes(p.oe[0], p.tok)
+               case "base", "basefont", "bgsound", "command", "link", "meta", "noframes", "script", "style", "title":
+                       return inHeadIM(p)
+               case "body":
+                       if len(p.oe) >= 2 {
+                               body := p.oe[1]
+                               if body.Type == ElementNode && body.Data == "body" {
+                                       p.framesetOK = false
+                                       copyAttributes(body, p.tok)
+                               }
+                       }
+               case "frameset":
+                       if !p.framesetOK || len(p.oe) < 2 || p.oe[1].Data != "body" {
+                               // Ignore the token.
+                               return true
+                       }
+                       body := p.oe[1]
+                       if body.Parent != nil {
+                               body.Parent.Remove(body)
+                       }
+                       p.oe = p.oe[:1]
+                       p.addElement(p.tok.Data, p.tok.Attr)
+                       p.im = inFramesetIM
+                       return true
                case "address", "article", "aside", "blockquote", "center", "details", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section", "summary", "ul":
                        p.popUntil(buttonScope, "p")
                        p.addElement(p.tok.Data, p.tok.Attr)
@@ -758,29 +781,6 @@ func inBodyIM(p *parser) bool {
                        }
                        p.reconstructActiveFormattingElements()
                        p.addElement(p.tok.Data, p.tok.Attr)
-               case "body":
-                       if len(p.oe) >= 2 {
-                               body := p.oe[1]
-                               if body.Type == ElementNode && body.Data == "body" {
-                                       p.framesetOK = false
-                                       copyAttributes(body, p.tok)
-                               }
-                       }
-               case "frameset":
-                       if !p.framesetOK || len(p.oe) < 2 || p.oe[1].Data != "body" {
-                               // Ignore the token.
-                               return true
-                       }
-                       body := p.oe[1]
-                       if body.Parent != nil {
-                               body.Parent.Remove(body)
-                       }
-                       p.oe = p.oe[:1]
-                       p.addElement(p.tok.Data, p.tok.Attr)
-                       p.im = inFramesetIM
-                       return true
-               case "base", "basefont", "bgsound", "command", "link", "meta", "noframes", "script", "style", "title":
-                       return inHeadIM(p)
                case "image":
                        p.tok.Data = "img"
                        return false
@@ -847,8 +847,14 @@ func inBodyIM(p *parser) bool {
        case EndTagToken:
                switch p.tok.Data {
                case "body":
-                       // TODO: autoclose the stack of open elements.
-                       p.im = afterBodyIM
+                       if p.elementInScope(defaultScope, "body") {
+                               p.im = afterBodyIM
+                       }
+               case "html":
+                       if p.elementInScope(defaultScope, "body") {
+                               p.parseImpliedToken(EndTagToken, "body", nil)
+                               return false
+                       }
                        return true
                case "p":
                        if !p.elementInScope(buttonScope, "p") {
index ddaae4041c9f4f7072cd7290fcaeb6e28aad8ba8..d8ff9dd2050081697e48a64c828360c481e7421a 100644 (file)
@@ -2,7 +2,7 @@ PASS "<!DOCTYPE html><p><b><i><u></p> <p>X"
 PASS "<p><b><i><u></p>\n<p>X"
 PASS "<!doctype html></html> <head>"
 PASS "<!doctype html></body><meta>"
-FAIL "<html></html><!-- foo -->"
+PASS "<html></html><!-- foo -->"
 PASS "<!doctype html></body><title>X</title>"
 PASS "<!doctype html><table> X<meta></table>"
 PASS "<!doctype html><table> x</table>"
index 5cdf79345ae69e9a6fed688ae2f761c72da1eec3..088684bc0cfe41e7d9dfa7d7cb6ebf4b5bef7823 100644 (file)
@@ -21,7 +21,7 @@ PASS "<body></body></br foo=\"bar\">"
 PASS "<bdy></body><br foo=\"bar\">"
 PASS "<html><body></body></html><!-- Hi there -->"
 PASS "<html><body></body></html>x<!-- Hi there -->"
-FAIL "<html><body></body></html>x<!-- Hi there --></html><!-- Again -->"
+PASS "<html><body></body></html>x<!-- Hi there --></html><!-- Again -->"
 PASS "<html><body></body></html>x<!-- Hi there --></body></html><!-- Again -->"
 FAIL "<html><body><ruby><div><rp>xx</rp></div></ruby></body></html>"
 FAIL "<html><body><ruby><div><rt>xx</rt></div></ruby></body></html>"