]> Cypherpunks repositories - gostls13.git/commitdiff
html/template: fix panic on Clone
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 13 Mar 2012 23:55:43 +0000 (16:55 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 13 Mar 2012 23:55:43 +0000 (16:55 -0700)
Fixes #3281

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5819044

src/pkg/html/template/clone_test.go
src/pkg/html/template/template.go

index c612775d4f01fba832c3f195eebcc045b02809df..5907ff2c3eb1cd42fcf2c91f6e02ea9eb5e0940e 100644 (file)
@@ -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()
+}
index b0bae7a54fb35e4d47e0ced052c7832bbf60f9d2..95a3027c46a183aa46790ecff1bb78bc8855586c 100644 (file)
@@ -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,