Commit 5f32c8b8 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

html/template: fix panic on Clone

Fixes #3281

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5819044
parent d6ad6f0e
...@@ -113,3 +113,10 @@ func TestClone(t *testing.T) { ...@@ -113,3 +113,10 @@ func TestClone(t *testing.T) {
t.Errorf("t3: got %q want %q", got, want) t.Errorf("t3: got %q want %q", got, want)
} }
} }
// This used to crash; http://golang.org/issue/3281
func TestCloneCrash(t *testing.T) {
t1 := New("all")
Must(t1.New("t1").Parse(`{{define "foo"}}foo{{end}}`))
t1.Clone()
}
...@@ -160,9 +160,11 @@ func (t *Template) Clone() (*Template, error) { ...@@ -160,9 +160,11 @@ func (t *Template) Clone() (*Template, error) {
if src == nil || src.escaped { if src == nil || src.escaped {
return nil, fmt.Errorf("html/template: cannot Clone %q after it has executed", t.Name()) return nil, fmt.Errorf("html/template: cannot Clone %q after it has executed", t.Name())
} }
x.Tree = &parse.Tree{ if x.Tree != nil {
Name: x.Tree.Name, x.Tree = &parse.Tree{
Root: x.Tree.Root.CopyList(), Name: x.Tree.Name,
Root: x.Tree.Root.CopyList(),
}
} }
ret.set[name] = &Template{ ret.set[name] = &Template{
false, false,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment