mirror of
https://github.com/golang/go
synced 2024-11-26 07:57:57 -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:
parent
421b75c0db
commit
bcccad4020
@ -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()
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user