aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/text/template/parse/parse.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2013-09-17 14:19:44 +1000
committerRob Pike <r@golang.org>2013-09-17 14:19:44 +1000
commiteeb758546e10b33be161e76b3c3290dbb7a70a87 (patch)
treeec2aac03c9a40ab8fba44c693e3ca6d5e8b1d6a9 /src/pkg/text/template/parse/parse.go
parent8d5ec52e6cf3a259b9054ee3c3621834f2491860 (diff)
downloadgo-eeb758546e10b33be161e76b3c3290dbb7a70a87.tar.xz
text/template/parse, html/template: copy Tree.text during html template clone
The root cause of the panic reported in https://code.google.com/p/go/issues/detail?id=5980 is that parse's Tree.Text wasn't being copied during the clone. Fix this by adding and using a Copy method for parse.Tree. Fixes #5980. R=golang-dev, r CC=golang-dev https://golang.org/cl/12420044
Diffstat (limited to 'src/pkg/text/template/parse/parse.go')
-rw-r--r--src/pkg/text/template/parse/parse.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/pkg/text/template/parse/parse.go b/src/pkg/text/template/parse/parse.go
index be83e77cf5..34112fb7b3 100644
--- a/src/pkg/text/template/parse/parse.go
+++ b/src/pkg/text/template/parse/parse.go
@@ -30,6 +30,19 @@ type Tree struct {
vars []string // variables defined at the moment.
}
+// Copy returns a copy of the Tree. Any parsing state is discarded.
+func (t *Tree) Copy() *Tree {
+ if t == nil {
+ return nil
+ }
+ return &Tree{
+ Name: t.Name,
+ ParseName: t.ParseName,
+ Root: t.Root.CopyList(),
+ text: t.text,
+ }
+}
+
// Parse returns a map from template name to parse.Tree, created by parsing the
// templates described in the argument string. The top-level template will be
// given the specified name. If an error is encountered, parsing stops and an