1
0
mirror of https://github.com/golang/go synced 2024-11-22 13:14:55 -07:00

text/template: fix nil crash on Templates

Fixes #3872.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6612060
This commit is contained in:
Rob Pike 2012-10-07 09:26:59 +11:00
parent 421b75c0db
commit bcccad4020
2 changed files with 8 additions and 0 deletions

View File

@ -811,3 +811,8 @@ func TestTree(t *testing.T) {
t.Errorf("expected %q got %q", expect, result)
}
}
func TestExecuteOnNewTemplate(t *testing.T) {
// This is issue 3872.
_ = New("Name").Templates()
}

View File

@ -117,6 +117,9 @@ func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error
// Templates returns a slice of the templates associated with t, including t
// itself.
func (t *Template) Templates() []*Template {
if t.common == nil {
return nil
}
// Return a slice so we don't expose the map.
m := make([]*Template, 0, len(t.tmpl))
for _, v := range t.tmpl {