Skip to content

Commit 8d16fa6

Browse files
namusyakanigeltao
authored andcommitted
html: avoid invalid nil pointer access
Updates golang/go#23071 Change-Id: I73d7302c5bde4441aa824093fdcce52e8bb51e31 Reviewed-on: https://go-review.googlesource.com/107379 Run-TryBot: Kunpei Sakai <[email protected]> Reviewed-by: Nigel Tao <[email protected]>
1 parent 3121141 commit 8d16fa6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

html/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,7 @@ func ParseFragment(r io.Reader, context *Node) ([]*Node, error) {
22702270
}
22712271
p.doc.AppendChild(root)
22722272
p.oe = nodeStack{root}
2273-
if context.DataAtom == a.Template {
2273+
if context != nil && context.DataAtom == a.Template {
22742274
p.templateStack = append(p.templateStack, inTemplateIM)
22752275
}
22762276
p.resetInsertionMode()

html/parse_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ func TestNodeConsistency(t *testing.T) {
380380
}
381381
}
382382

383+
func TestParseFragmentWithNilContext(t *testing.T) {
384+
// This shouldn't panic.
385+
ParseFragment(strings.NewReader("<p>hello</p>"), nil)
386+
}
387+
383388
func BenchmarkParser(b *testing.B) {
384389
buf, err := ioutil.ReadFile("testdata/go1.html")
385390
if err != nil {

0 commit comments

Comments
 (0)