mirror of
https://github.com/golang/net.git
synced 2026-04-01 02:47:08 +09:00
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 <namusyaka@gmail.com> Reviewed-by: Nigel Tao <nigeltao@golang.org>
This commit is contained in:
@@ -2270,7 +2270,7 @@ func ParseFragment(r io.Reader, context *Node) ([]*Node, error) {
|
||||
}
|
||||
p.doc.AppendChild(root)
|
||||
p.oe = nodeStack{root}
|
||||
if context.DataAtom == a.Template {
|
||||
if context != nil && context.DataAtom == a.Template {
|
||||
p.templateStack = append(p.templateStack, inTemplateIM)
|
||||
}
|
||||
p.resetInsertionMode()
|
||||
|
||||
@@ -380,6 +380,11 @@ func TestNodeConsistency(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFragmentWithNilContext(t *testing.T) {
|
||||
// This shouldn't panic.
|
||||
ParseFragment(strings.NewReader("<p>hello</p>"), nil)
|
||||
}
|
||||
|
||||
func BenchmarkParser(b *testing.B) {
|
||||
buf, err := ioutil.ReadFile("testdata/go1.html")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user