mirror of
https://github.com/golang/net.git
synced 2026-03-31 10:27:08 +09:00
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 <namusyaka@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org>
This commit is contained in:
@@ -860,9 +860,13 @@ func inBodyIM(p *parser) bool {
|
||||
// The newline, if any, will be dealt with by the TextToken case.
|
||||
p.framesetOK = false
|
||||
case a.Form:
|
||||
if p.oe.contains(a.Template) || p.form == nil {
|
||||
p.popUntil(buttonScope, a.P)
|
||||
p.addElement()
|
||||
if p.form != nil && !p.oe.contains(a.Template) {
|
||||
// Ignore the token
|
||||
return true
|
||||
}
|
||||
p.popUntil(buttonScope, a.P)
|
||||
p.addElement()
|
||||
if !p.oe.contains(a.Template) {
|
||||
p.form = p.top()
|
||||
}
|
||||
case a.Li:
|
||||
@@ -1098,12 +1102,13 @@ func inBodyIM(p *parser) bool {
|
||||
p.popUntil(defaultScope, p.tok.DataAtom)
|
||||
case a.Form:
|
||||
if p.oe.contains(a.Template) {
|
||||
if !p.oe.contains(a.Form) {
|
||||
i := p.indexOfElementInScope(defaultScope, a.Form)
|
||||
if i == -1 {
|
||||
// Ignore the token.
|
||||
return true
|
||||
}
|
||||
p.generateImpliedEndTags()
|
||||
if p.tok.DataAtom == a.Form {
|
||||
if p.oe[i].DataAtom != a.Form {
|
||||
// Ignore the token.
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -203,34 +203,36 @@ func dump(n *Node) (string, error) {
|
||||
return b.String(), nil
|
||||
}
|
||||
|
||||
const testDataDir = "testdata/webkit/"
|
||||
var testDataDirs = []string{"testdata/webkit/", "testdata/go/"}
|
||||
|
||||
func TestParser(t *testing.T) {
|
||||
testFiles, err := filepath.Glob(testDataDir + "*.dat")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tf := range testFiles {
|
||||
f, err := os.Open(tf)
|
||||
for _, testDataDir := range testDataDirs {
|
||||
testFiles, err := filepath.Glob(testDataDir + "*.dat")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
r := bufio.NewReader(f)
|
||||
|
||||
for i := 0; ; i++ {
|
||||
text, want, context, err := readParseTest(r)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
for _, tf := range testFiles {
|
||||
f, err := os.Open(tf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
r := bufio.NewReader(f)
|
||||
|
||||
err = testParseCase(text, want, context)
|
||||
for i := 0; ; i++ {
|
||||
text, want, context, err := readParseTest(r)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%s test #%d %q, %s", tf, i, text, err)
|
||||
err = testParseCase(text, want, context)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%s test #%d %q, %s", tf, i, text, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
html/testdata/go/template.dat
vendored
Normal file
13
html/testdata/go/template.dat
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
#data
|
||||
<body><template><yt-icon-button></yt-icon-button><form><paper-input></paper-input></form><style></style></template>
|
||||
#errors
|
||||
#document
|
||||
| <html>
|
||||
| <head>
|
||||
| <body>
|
||||
| <template>
|
||||
| content
|
||||
| <yt-icon-button>
|
||||
| <form>
|
||||
| <paper-input>
|
||||
| <style>
|
||||
Reference in New Issue
Block a user