From 7d63ff09a5ce65c91021acaf79b1d281cba55f07 Mon Sep 17 00:00:00 2001 From: Andrew Balholm Date: Fri, 20 Apr 2012 10:48:10 +1000 Subject: [PATCH] exp/html: improve afterHeadIM Clean up the flow of control. Fix the TODO for handling tags. Add a case to ignore doctype declarations. Pass one additional test. R=nigeltao CC=golang-dev https://golang.org/cl/6072047 --- src/pkg/exp/html/parse.go | 39 ++++++++--------------- src/pkg/exp/html/testlogs/tests19.dat.log | 2 +- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/pkg/exp/html/parse.go b/src/pkg/exp/html/parse.go index 72963a5f5d..8f62348969 100644 --- a/src/pkg/exp/html/parse.go +++ b/src/pkg/exp/html/parse.go @@ -539,16 +539,7 @@ func inHeadIM(p *parser) bool { // Section 12.2.5.4.6. func afterHeadIM(p *parser) bool { - var ( - add bool - attr []Attribute - framesetOK bool - implied bool - ) switch p.tok.Type { - case ErrorToken: - implied = true - framesetOK = true case TextToken: s := strings.TrimLeft(p.tok.Data, whitespace) if len(s) < len(p.tok.Data) { @@ -559,16 +550,15 @@ func afterHeadIM(p *parser) bool { } p.tok.Data = s } - implied = true - framesetOK = true case StartTagToken: switch p.tok.Data { case "html": - // TODO. + return inBodyIM(p) case "body": - add = true - attr = p.tok.Attr - framesetOK = false + p.addElement(p.tok.Data, p.tok.Attr) + p.framesetOK = false + p.im = inBodyIM + return true case "frameset": p.addElement(p.tok.Data, p.tok.Attr) p.im = inFramesetIM @@ -580,15 +570,11 @@ func afterHeadIM(p *parser) bool { case "head": // Ignore the token. return true - default: - implied = true - framesetOK = true } case EndTagToken: switch p.tok.Data { case "body", "html", "br": - implied = true - framesetOK = true + // Drop down to creating an implied tag. default: // Ignore the token. return true @@ -599,13 +585,14 @@ func afterHeadIM(p *parser) bool { Data: p.tok.Data, }) return true + case DoctypeToken: + // Ignore the token. + return true } - if add || implied { - p.addElement("body", attr) - p.framesetOK = framesetOK - } - p.im = inBodyIM - return !implied + + p.parseImpliedToken(StartTagToken, "body", nil) + p.framesetOK = true + return false } // copyAttributes copies attributes of src not found on dst to dst. diff --git a/src/pkg/exp/html/testlogs/tests19.dat.log b/src/pkg/exp/html/testlogs/tests19.dat.log index 45269a870a..189e0fe4a8 100644 --- a/src/pkg/exp/html/testlogs/tests19.dat.log +++ b/src/pkg/exp/html/testlogs/tests19.dat.log @@ -85,7 +85,7 @@ PASS "" PASS "" FAIL "" PASS "" -FAIL "" +PASS "" PASS "" PASS "abcdef" PASS "
ab
cdef" -- 2.48.1