Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions html/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ func inBodyIM(p *parser) bool {
p.acknowledgeSelfClosingTag()
p.framesetOK = false
case a.Input:
if p.fragment && p.context.DataAtom == a.Select {
if p.fragment && p.context != nil && p.context.DataAtom == a.Select {
// Ignore the token.
return true
}
Expand Down Expand Up @@ -1110,7 +1110,7 @@ func inBodyIM(p *parser) bool {
// Don't let the tokenizer go into raw text mode when scripting is disabled.
p.tokenizer.NextIsNotRawText()
case a.Select:
if p.fragment && p.context.DataAtom == a.Select {
if p.fragment && p.context != nil && p.context.DataAtom == a.Select {
// Ignore the token.
return true
} else if p.popUntil(defaultScope, a.Select) {
Expand Down
13 changes: 11 additions & 2 deletions html/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,17 @@ func TestNodeConsistency(t *testing.T) {
}

func TestParseFragmentWithNilContext(t *testing.T) {
// This shouldn't panic.
ParseFragment(strings.NewReader("<p>hello</p>"), nil)
srcs := []string{
"<p>hello</p>",
"<input>",
"<select>",
}
for _, src := range srcs {
// This shouldn't panic.
if _, err := ParseFragment(strings.NewReader(src), nil); err != nil {
t.Errorf("ParseFragment(%q, nil): %v", src, err)
}
}
}

func TestParseFragmentForeignContentTemplates(t *testing.T) {
Expand Down
Loading