]> Cypherpunks repositories - gostls13.git/commitdiff
html/template: update the Tree field after parsing new templates
authorRob Pike <r@golang.org>
Wed, 25 Sep 2013 00:00:09 +0000 (10:00 +1000)
committerRob Pike <r@golang.org>
Wed, 25 Sep 2013 00:00:09 +0000 (10:00 +1000)
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

src/pkg/html/template/escape_test.go
src/pkg/html/template/template.go

index befdb215bedd0bd13728e049effe5a67de91980e..58383a6cd4e291454d659776b8fca56d8778face 100644 (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)
index db7244e4249e8dc084d3386ef8114836f76253b3..11cc34a50a38eb80297d54da58808bbe39c07625 100644 (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
 }