diff options
Diffstat (limited to 'libgo/go/html/template/template.go')
-rw-r--r-- | libgo/go/html/template/template.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/libgo/go/html/template/template.go b/libgo/go/html/template/template.go index e183898d50f..11cc34a50a3 100644 --- a/libgo/go/html/template/template.go +++ b/libgo/go/html/template/template.go @@ -21,7 +21,9 @@ type Template struct { // We could embed the text/template field, but it's safer not to because // we need to keep our version of the name space and the underlying // template's in sync. - text *template.Template + text *template.Template + // The underlying template's parse tree, updated to be HTML-safe. + Tree *parse.Tree *nameSpace // common to all associated templates } @@ -126,8 +128,10 @@ func (t *Template) Parse(src string) (*Template, error) { if tmpl == nil { tmpl = t.new(name) } + // Restore our record of this text/template to its unescaped original state. tmpl.escaped = false tmpl.text = v + tmpl.Tree = v.Tree } return t, nil } @@ -149,6 +153,7 @@ func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error ret := &Template{ false, text, + text.Tree, t.nameSpace, } t.set[name] = ret @@ -176,6 +181,7 @@ func (t *Template) Clone() (*Template, error) { ret := &Template{ false, textClone, + textClone.Tree, &nameSpace{ set: make(map[string]*Template), }, @@ -186,15 +192,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()) } - if x.Tree != nil { - x.Tree = &parse.Tree{ - Name: x.Tree.Name, - Root: x.Tree.Root.CopyList(), - } - } + x.Tree = x.Tree.Copy() ret.set[name] = &Template{ false, x, + x.Tree, ret.nameSpace, } } @@ -206,6 +208,7 @@ func New(name string) *Template { tmpl := &Template{ false, template.New(name), + nil, &nameSpace{ set: make(map[string]*Template), }, @@ -228,6 +231,7 @@ func (t *Template) new(name string) *Template { tmpl := &Template{ false, t.text.New(name), + nil, t.nameSpace, } tmpl.set[name] = tmpl |