Skip to content

Commit 32a936f

Browse files
namusyakanigeltao
authored andcommitted
html: don't ignore the token if the current node is form
See: https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody Fixes golang/go#25703 Updates golang/go#23071 Change-Id: I09db4c2d07a242cb45c3e37b499c609809dd0b83 Reviewed-on: https://go-review.googlesource.com/120658 Run-TryBot: Kunpei Sakai <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Nigel Tao <[email protected]>
1 parent 7d20a46 commit 32a936f

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

html/parse.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,13 @@ func inBodyIM(p *parser) bool {
860860
// The newline, if any, will be dealt with by the TextToken case.
861861
p.framesetOK = false
862862
case a.Form:
863-
if p.oe.contains(a.Template) || p.form == nil {
864-
p.popUntil(buttonScope, a.P)
865-
p.addElement()
863+
if p.form != nil && !p.oe.contains(a.Template) {
864+
// Ignore the token
865+
return true
866+
}
867+
p.popUntil(buttonScope, a.P)
868+
p.addElement()
869+
if !p.oe.contains(a.Template) {
866870
p.form = p.top()
867871
}
868872
case a.Li:
@@ -1098,12 +1102,13 @@ func inBodyIM(p *parser) bool {
10981102
p.popUntil(defaultScope, p.tok.DataAtom)
10991103
case a.Form:
11001104
if p.oe.contains(a.Template) {
1101-
if !p.oe.contains(a.Form) {
1105+
i := p.indexOfElementInScope(defaultScope, a.Form)
1106+
if i == -1 {
11021107
// Ignore the token.
11031108
return true
11041109
}
11051110
p.generateImpliedEndTags()
1106-
if p.tok.DataAtom == a.Form {
1111+
if p.oe[i].DataAtom != a.Form {
11071112
// Ignore the token.
11081113
return true
11091114
}

html/parse_test.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -203,34 +203,36 @@ func dump(n *Node) (string, error) {
203203
return b.String(), nil
204204
}
205205

206-
const testDataDir = "testdata/webkit/"
206+
var testDataDirs = []string{"testdata/webkit/", "testdata/go/"}
207207

208208
func TestParser(t *testing.T) {
209-
testFiles, err := filepath.Glob(testDataDir + "*.dat")
210-
if err != nil {
211-
t.Fatal(err)
212-
}
213-
for _, tf := range testFiles {
214-
f, err := os.Open(tf)
209+
for _, testDataDir := range testDataDirs {
210+
testFiles, err := filepath.Glob(testDataDir + "*.dat")
215211
if err != nil {
216212
t.Fatal(err)
217213
}
218-
defer f.Close()
219-
r := bufio.NewReader(f)
220-
221-
for i := 0; ; i++ {
222-
text, want, context, err := readParseTest(r)
223-
if err == io.EOF {
224-
break
225-
}
214+
for _, tf := range testFiles {
215+
f, err := os.Open(tf)
226216
if err != nil {
227217
t.Fatal(err)
228218
}
219+
defer f.Close()
220+
r := bufio.NewReader(f)
229221

230-
err = testParseCase(text, want, context)
222+
for i := 0; ; i++ {
223+
text, want, context, err := readParseTest(r)
224+
if err == io.EOF {
225+
break
226+
}
227+
if err != nil {
228+
t.Fatal(err)
229+
}
231230

232-
if err != nil {
233-
t.Errorf("%s test #%d %q, %s", tf, i, text, err)
231+
err = testParseCase(text, want, context)
232+
233+
if err != nil {
234+
t.Errorf("%s test #%d %q, %s", tf, i, text, err)
235+
}
234236
}
235237
}
236238
}

html/testdata/go/template.dat

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#data
2+
<body><template><yt-icon-button></yt-icon-button><form><paper-input></paper-input></form><style></style></template>
3+
#errors
4+
#document
5+
| <html>
6+
| <head>
7+
| <body>
8+
| <template>
9+
| content
10+
| <yt-icon-button>
11+
| <form>
12+
| <paper-input>
13+
| <style>

0 commit comments

Comments
 (0)