Skip to content

Commit

Permalink
html/template: fix panic on Clone
Browse files Browse the repository at this point in the history
Fixes #3281

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5819044
  • Loading branch information
bradfitz committed Mar 13, 2012
1 parent d6ad6f0 commit 5f32c8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/pkg/html/template/clone_test.go
Expand Up @@ -113,3 +113,10 @@ func TestClone(t *testing.T) {
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()
}
8 changes: 5 additions & 3 deletions src/pkg/html/template/template.go
Expand Up @@ -160,9 +160,11 @@ func (t *Template) Clone() (*Template, error) {
if src == nil || src.escaped {
return nil, fmt.Errorf("html/template: cannot Clone %q after it has executed", t.Name())
}
x.Tree = &parse.Tree{
Name: x.Tree.Name,
Root: x.Tree.Root.CopyList(),
if x.Tree != nil {
x.Tree = &parse.Tree{
Name: x.Tree.Name,
Root: x.Tree.Root.CopyList(),
}
}
ret.set[name] = &Template{
false,
Expand Down

0 comments on commit 5f32c8b

Please sign in to comment.