diff options
| author | Rob Pike <r@golang.org> | 2012-10-07 09:26:59 +1100 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2012-10-07 09:26:59 +1100 |
| commit | bcccad40202ba895d237d9d0a921b33bc2c5601f (patch) | |
| tree | 419f60094df08faa86a8952666d16accc2c0a576 /src/pkg/text | |
| parent | 421b75c0dbab3460dbfdb023d67ce0807c4d5327 (diff) | |
| download | go-bcccad40202ba895d237d9d0a921b33bc2c5601f.tar.xz | |
text/template: fix nil crash on Templates
Fixes #3872.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6612060
Diffstat (limited to 'src/pkg/text')
| -rw-r--r-- | src/pkg/text/template/exec_test.go | 5 | ||||
| -rw-r--r-- | src/pkg/text/template/template.go | 3 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/pkg/text/template/exec_test.go b/src/pkg/text/template/exec_test.go index d79365107d..683e9ac76b 100644 --- a/src/pkg/text/template/exec_test.go +++ b/src/pkg/text/template/exec_test.go @@ -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() +} diff --git a/src/pkg/text/template/template.go b/src/pkg/text/template/template.go index 82fc9e5e39..a2b9062ad1 100644 --- a/src/pkg/text/template/template.go +++ b/src/pkg/text/template/template.go @@ -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 { |
