Commit e2e9d1d6 authored by Rob Pike's avatar Rob Pike

html/template: update the Tree field after parsing new templates

After text/template.Parse, all the templates may have changed, so
we need to set them all back to their unescaped state. The code
did this but (mea culpa) forgot to set the Tree field of the html/template
struct.

Since the Tree is reset during escaping, this only matters if an error
arises during escaping and we want to print a message.

Fixes #6459.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/13877043
parent 20db0f42
...@@ -655,6 +655,11 @@ func TestEscape(t *testing.T) { ...@@ -655,6 +655,11 @@ func TestEscape(t *testing.T) {
for _, test := range tests { for _, test := range tests {
tmpl := New(test.name) tmpl := New(test.name)
tmpl = Must(tmpl.Parse(test.input)) tmpl = Must(tmpl.Parse(test.input))
// Check for bug 6459: Tree field was not set in Parse.
if tmpl.Tree != tmpl.text.Tree {
t.Errorf("%s: tree not set properly", test.name)
continue
}
b := new(bytes.Buffer) b := new(bytes.Buffer)
if err := tmpl.Execute(b, data); err != nil { if err := tmpl.Execute(b, data); err != nil {
t.Errorf("%s: template execution failed: %s", test.name, err) t.Errorf("%s: template execution failed: %s", test.name, err)
......
...@@ -128,8 +128,10 @@ func (t *Template) Parse(src string) (*Template, error) { ...@@ -128,8 +128,10 @@ func (t *Template) Parse(src string) (*Template, error) {
if tmpl == nil { if tmpl == nil {
tmpl = t.new(name) tmpl = t.new(name)
} }
// Restore our record of this text/template to its unescaped original state.
tmpl.escaped = false tmpl.escaped = false
tmpl.text = v tmpl.text = v
tmpl.Tree = v.Tree
} }
return t, nil return t, nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment