From b15a1e3cfb64aeeb90f74e0748524b38fde5ebf9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Bohusl=C3=A1vek?= Date: Thu, 23 Aug 2018 19:51:50 +0200 Subject: [PATCH] text/template: Put bad function name in quotes in panic from (*Template).Funcs This turns panic: function name is not a valid identifier into panic: function name "" is not a valid identifier and also makes it consistent with the func signature check. This CL also makes the testBadFuncName func a test helper. Change-Id: Id967cb61ac28228de81e1cd76a39f5195a5ebd11 Reviewed-on: https://go-review.googlesource.com/130998 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/text/template/exec_test.go | 1 + src/text/template/funcs.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go index 6f40d80635..648ad8ff03 100644 --- a/src/text/template/exec_test.go +++ b/src/text/template/exec_test.go @@ -1279,6 +1279,7 @@ func TestBadFuncNames(t *testing.T) { } func testBadFuncName(name string, t *testing.T) { + t.Helper() defer func() { recover() }() diff --git a/src/text/template/funcs.go b/src/text/template/funcs.go index abddfa1141..31fe77a327 100644 --- a/src/text/template/funcs.go +++ b/src/text/template/funcs.go @@ -65,7 +65,7 @@ func createValueFuncs(funcMap FuncMap) map[string]reflect.Value { func addValueFuncs(out map[string]reflect.Value, in FuncMap) { for name, fn := range in { if !goodName(name) { - panic(fmt.Errorf("function name %s is not a valid identifier", name)) + panic(fmt.Errorf("function name %q is not a valid identifier", name)) } v := reflect.ValueOf(fn) if v.Kind() != reflect.Func { -- 2.50.0