aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/html
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2013-09-25 10:00:09 +1000
committerRob Pike <r@golang.org>2013-09-25 10:00:09 +1000
commite2e9d1d6841d4ee937568eeb73a9b43e73e88ad3 (patch)
tree04354b5e9cd63ba4f8a5bd29f076302fc50fce8c /src/pkg/html
parent20db0f428a28a529146b5016b97061f2b13c54d4 (diff)
downloadgo-e2e9d1d6841d4ee937568eeb73a9b43e73e88ad3.tar.xz
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
Diffstat (limited to 'src/pkg/html')
-rw-r--r--src/pkg/html/template/escape_test.go5
-rw-r--r--src/pkg/html/template/template.go2
2 files changed, 7 insertions, 0 deletions
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
}