]> Cypherpunks repositories - gostls13.git/commitdiff
html: allow whitespace between head and body
authorAndrew Balholm <andybalholm@gmail.com>
Fri, 2 Dec 2011 00:46:24 +0000 (11:46 +1100)
committerNigel Tao <nigeltao@golang.org>
Fri, 2 Dec 2011 00:46:24 +0000 (11:46 +1100)
Also ignore <head> tag after </head>.

Pass tests6.dat, test 0:
<!doctype html></head> <head>

| <!DOCTYPE html>
| <html>
|   <head>
|   " "
|   <body>

Also pass tests through test 6:
<body>
<div>

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

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

index 97fbc514d827abc75ba8b81a79c325afe6ace497..dd2d8165bdb3d732d4998285af62c5d992b37d47 100644 (file)
@@ -515,7 +515,19 @@ func afterHeadIM(p *parser) bool {
                implied    bool
        )
        switch p.tok.Type {
-       case ErrorToken, TextToken:
+       case ErrorToken:
+               implied = true
+               framesetOK = true
+       case TextToken:
+               s := strings.TrimLeft(p.tok.Data, whitespace)
+               if len(s) < len(p.tok.Data) {
+                       // Add the initial whitespace to the current node.
+                       p.addText(p.tok.Data[:len(p.tok.Data)-len(s)])
+                       if s == "" {
+                               return true
+                       }
+                       p.tok.Data = s
+               }
                implied = true
                framesetOK = true
        case StartTagToken:
@@ -535,7 +547,8 @@ func afterHeadIM(p *parser) bool {
                        defer p.oe.pop()
                        return inHeadIM(p)
                case "head":
-                       // TODO.
+                       // Ignore the token.
+                       return true
                default:
                        implied = true
                        framesetOK = true
index e0c19cff6da5f91deccd66de4cfe7fd694dcb764..5062a6edcb88f29e63c3cead6df3f44e87a73654 100644 (file)
@@ -167,6 +167,7 @@ func TestParser(t *testing.T) {
                {"tests3.dat", -1},
                {"tests4.dat", -1},
                {"tests5.dat", -1},
+               {"tests6.dat", 7},
        }
        for _, tf := range testFiles {
                f, err := os.Open("testdata/webkit/" + tf.filename)