Commit e1a5aa81 authored by Robert Figueiredo's avatar Robert Figueiredo Committed by Rob Pike

html/template: Ensure release of namespace mutex in Template.Execute()

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6727046
parent f878b67b
...@@ -45,18 +45,24 @@ func (t *Template) Templates() []*Template { ...@@ -45,18 +45,24 @@ func (t *Template) Templates() []*Template {
return m return m
} }
// Execute applies a parsed template to the specified data object, // escape escapes all associated templates.
// writing the output to wr. func (t *Template) escape() error {
func (t *Template) Execute(wr io.Writer, data interface{}) (err error) {
t.nameSpace.mu.Lock() t.nameSpace.mu.Lock()
defer t.nameSpace.mu.Unlock()
if !t.escaped { if !t.escaped {
if err = escapeTemplates(t, t.Name()); err != nil { if err := escapeTemplates(t, t.Name()); err != nil {
t.escaped = true return err
} }
t.escaped = true
} }
t.nameSpace.mu.Unlock() return nil
if err != nil { }
return
// Execute applies a parsed template to the specified data object,
// writing the output to wr.
func (t *Template) Execute(wr io.Writer, data interface{}) error {
if err := t.escape(); err != nil {
return err
} }
return t.text.Execute(wr, data) return t.text.Execute(wr, data)
} }
......
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