diff --git a/src/pkg/text/template/exec_test.go b/src/pkg/text/template/exec_test.go index d79365107d3..683e9ac76b6 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 82fc9e5e39d..a2b9062ad14 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 {