mirror of
https://github.com/golang/go
synced 2024-11-26 01:07:57 -07:00
html/template: Ensure release of namespace mutex in Template.Execute()
R=golang-dev, r CC=golang-dev https://golang.org/cl/6727046
This commit is contained in:
parent
f878b67b0f
commit
e1a5aa8105
@ -45,18 +45,24 @@ func (t *Template) Templates() []*Template {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// escape escapes all associated templates.
|
||||||
|
func (t *Template) escape() error {
|
||||||
|
t.nameSpace.mu.Lock()
|
||||||
|
defer t.nameSpace.mu.Unlock()
|
||||||
|
if !t.escaped {
|
||||||
|
if err := escapeTemplates(t, t.Name()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
t.escaped = true
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Execute applies a parsed template to the specified data object,
|
// Execute applies a parsed template to the specified data object,
|
||||||
// writing the output to wr.
|
// writing the output to wr.
|
||||||
func (t *Template) Execute(wr io.Writer, data interface{}) (err error) {
|
func (t *Template) Execute(wr io.Writer, data interface{}) error {
|
||||||
t.nameSpace.mu.Lock()
|
if err := t.escape(); err != nil {
|
||||||
if !t.escaped {
|
return err
|
||||||
if err = escapeTemplates(t, t.Name()); err != nil {
|
|
||||||
t.escaped = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t.nameSpace.mu.Unlock()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
return t.text.Execute(wr, data)
|
return t.text.Execute(wr, data)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user