From: Rob Pike Date: Wed, 25 Sep 2013 00:00:09 +0000 (+1000) Subject: html/template: update the Tree field after parsing new templates X-Git-Tag: go1.2rc2~120 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e2e9d1d6841d4ee937568eeb73a9b43e73e88ad3;p=gostls13.git 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 --- diff --git a/src/pkg/html/template/escape_test.go b/src/pkg/html/template/escape_test.go index befdb215be..58383a6cd4 100644 --- a/src/pkg/html/template/escape_test.go +++ b/src/pkg/html/template/escape_test.go @@ -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) diff --git a/src/pkg/html/template/template.go b/src/pkg/html/template/template.go index db7244e424..11cc34a50a 100644 --- a/src/pkg/html/template/template.go +++ b/src/pkg/html/template/template.go @@ -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 }