1
0
mirror of https://github.com/golang/go synced 2024-11-11 22:20:22 -07:00

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
This commit is contained in:
Rob Pike 2013-09-25 10:00:09 +10:00
parent 20db0f428a
commit e2e9d1d684
2 changed files with 7 additions and 0 deletions

View File

@ -655,6 +655,11 @@ func TestEscape(t *testing.T) {
for _, test := range tests {
tmpl := New(test.name)
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)
if err := tmpl.Execute(b, data); err != nil {
t.Errorf("%s: template execution failed: %s", test.name, err)

View File

@ -128,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
}