diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2012-03-13 16:55:43 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2012-03-13 16:55:43 -0700 |
| commit | 5f32c8b88bfe5f6e2ba32bb444dbda88ec741024 (patch) | |
| tree | 594973aed2b0310e6a9c8f26d13628fe81c36bfe /src/pkg/html | |
| parent | d6ad6f0e61228152b3618af2e34381439d3b3ca0 (diff) | |
| download | go-5f32c8b88bfe5f6e2ba32bb444dbda88ec741024.tar.xz | |
html/template: fix panic on Clone
Fixes #3281
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5819044
Diffstat (limited to 'src/pkg/html')
| -rw-r--r-- | src/pkg/html/template/clone_test.go | 7 | ||||
| -rw-r--r-- | src/pkg/html/template/template.go | 8 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/pkg/html/template/clone_test.go b/src/pkg/html/template/clone_test.go index c612775d4f..5907ff2c3e 100644 --- a/src/pkg/html/template/clone_test.go +++ b/src/pkg/html/template/clone_test.go @@ -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() +} diff --git a/src/pkg/html/template/template.go b/src/pkg/html/template/template.go index b0bae7a54f..95a3027c46 100644 --- a/src/pkg/html/template/template.go +++ b/src/pkg/html/template/template.go @@ -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, |
