From: Andrew Balholm Date: Mon, 13 Aug 2012 23:53:10 +0000 (+1000) Subject: exp/html: generate replacement for correctly X-Git-Tag: go1.1rc2~2653 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3ba25e76a7dbb1574006081f597dcc6d9b569869;p=gostls13.git exp/html: generate replacement for correctly When generating replacement elements for an tag, the old addSyntheticElement method was producing the wrong nesting. Replace it with parseImpliedToken. Pass the one remaining test in the test suite. R=nigeltao CC=golang-dev https://golang.org/cl/6453114 --- diff --git a/src/pkg/exp/html/parse.go b/src/pkg/exp/html/parse.go index 1c40cd30a1..d4b1227768 100644 --- a/src/pkg/exp/html/parse.go +++ b/src/pkg/exp/html/parse.go @@ -19,9 +19,8 @@ type parser struct { tokenizer *Tokenizer // tok is the most recently read token. tok Token - // Self-closing tags like
are re-interpreted as a two-token sequence: - //
followed by . hasSelfClosingToken is true if we have just read - // the synthetic start tag and the next one due is the matching end tag. + // Self-closing tags like
are treated as start tags, except that + // hasSelfClosingToken is set while they are being processed. hasSelfClosingToken bool // doc is the document root element. doc *Node @@ -313,16 +312,6 @@ func (p *parser) addElement() { }) } -// addSyntheticElement adds a child element with the given tag and attributes. -func (p *parser) addSyntheticElement(tagAtom a.Atom, attr []Attribute) { - p.addChild(&Node{ - Type: ElementNode, - DataAtom: tagAtom, - Data: tagAtom.String(), - Attr: attr, - }) -} - // Section 12.2.3.3. func (p *parser) addFormattingElement() { tagAtom, attr := p.tok.DataAtom, p.tok.Attr @@ -935,22 +924,23 @@ func inBodyIM(p *parser) bool { } p.acknowledgeSelfClosingTag() p.popUntil(buttonScope, a.P) - p.addSyntheticElement(a.Form, nil) - p.form = p.top() + p.parseImpliedToken(StartTagToken, a.Form, a.Form.String()) if action != "" { p.form.Attr = []Attribute{{Key: "action", Val: action}} } - p.addSyntheticElement(a.Hr, nil) - p.oe.pop() - p.addSyntheticElement(a.Label, nil) + p.parseImpliedToken(StartTagToken, a.Hr, a.Hr.String()) + p.parseImpliedToken(StartTagToken, a.Label, a.Label.String()) p.addText(prompt) - p.addSyntheticElement(a.Input, attr) - p.oe.pop() - p.oe.pop() - p.addSyntheticElement(a.Hr, nil) + p.addChild(&Node{ + Type: ElementNode, + DataAtom: a.Input, + Data: a.Input.String(), + Attr: attr, + }) p.oe.pop() - p.oe.pop() - p.form = nil + p.parseImpliedToken(EndTagToken, a.Label, a.Label.String()) + p.parseImpliedToken(StartTagToken, a.Hr, a.Hr.String()) + p.parseImpliedToken(EndTagToken, a.Form, a.Form.String()) case a.Textarea: p.addElement() p.setOriginalIM() @@ -1036,7 +1026,7 @@ func inBodyIM(p *parser) bool { p.oe.remove(node) case a.P: if !p.elementInScope(buttonScope, a.P) { - p.addSyntheticElement(a.P, nil) + p.parseImpliedToken(StartTagToken, a.P, a.P.String()) } p.popUntil(buttonScope, a.P) case a.Li: diff --git a/src/pkg/exp/html/testlogs/webkit02.dat.log b/src/pkg/exp/html/testlogs/webkit02.dat.log index 72c04376a3..1aa0b39a61 100644 --- a/src/pkg/exp/html/testlogs/webkit02.dat.log +++ b/src/pkg/exp/html/testlogs/webkit02.dat.log @@ -9,5 +9,5 @@ PASS "
A" PASS "test" PASS "" PASS "