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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Michal Bohuslávek 2018-08-23 19:51:50 +02:00 committed by Brad Fitzpatrick
parent 4b439e41e2
commit b15a1e3cfb
2 changed files with 2 additions and 1 deletions

View File

@ -1279,6 +1279,7 @@ func TestBadFuncNames(t *testing.T) {
} }
func testBadFuncName(name string, t *testing.T) { func testBadFuncName(name string, t *testing.T) {
t.Helper()
defer func() { defer func() {
recover() recover()
}() }()

View File

@ -65,7 +65,7 @@ func createValueFuncs(funcMap FuncMap) map[string]reflect.Value {
func addValueFuncs(out map[string]reflect.Value, in FuncMap) { func addValueFuncs(out map[string]reflect.Value, in FuncMap) {
for name, fn := range in { for name, fn := range in {
if !goodName(name) { 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) v := reflect.ValueOf(fn)
if v.Kind() != reflect.Func { if v.Kind() != reflect.Func {