html: copy attributes from extra <html> tags to root element

Pass tests2.dat, test 50:
<!DOCTYPE html><html><body><html id=x>

| <!DOCTYPE html>
| <html>
|   id="x"
|   <head>
|   <body>

Also pass tests through test 56:
<!DOCTYPE html>X<p/x/y/z>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5432045
This commit is contained in:
Andrew Balholm 2011-11-22 12:08:22 +11:00 committed by Nigel Tao
parent 750de28d6c
commit 95e60acb97
2 changed files with 5 additions and 1 deletions

View File

@ -457,6 +457,8 @@ func inHeadIM(p *parser) bool {
implied = true implied = true
case StartTagToken: case StartTagToken:
switch p.tok.Data { switch p.tok.Data {
case "html":
return inBodyIM(p)
case "base", "basefont", "bgsound", "command", "link", "meta": case "base", "basefont", "bgsound", "command", "link", "meta":
p.addElement(p.tok.Data, p.tok.Attr) p.addElement(p.tok.Data, p.tok.Attr)
p.oe.pop() p.oe.pop()
@ -581,6 +583,8 @@ func inBodyIM(p *parser) bool {
p.framesetOK = false p.framesetOK = false
case StartTagToken: case StartTagToken:
switch p.tok.Data { switch p.tok.Data {
case "html":
copyAttributes(p.oe[0], p.tok)
case "address", "article", "aside", "blockquote", "center", "details", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section", "summary", "ul": 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(buttonScopeStopTags, "p") p.popUntil(buttonScopeStopTags, "p")
p.addElement(p.tok.Data, p.tok.Attr) p.addElement(p.tok.Data, p.tok.Attr)

View File

@ -134,7 +134,7 @@ func TestParser(t *testing.T) {
}{ }{
// 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", -1}, {"tests1.dat", -1},
{"tests2.dat", 50}, {"tests2.dat", 57},
{"tests3.dat", 0}, {"tests3.dat", 0},
} }
for _, tf := range testFiles { for _, tf := range testFiles {