]> Cypherpunks repositories - gostls13.git/commitdiff
text/template: Put bad function name in quotes in panic from (*Template).Funcs
authorMichal Bohuslávek <mbohuslavek@gmail.com>
Thu, 23 Aug 2018 17:51:50 +0000 (19:51 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 23 Aug 2018 19:24:40 +0000 (19:24 +0000)
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>

src/text/template/exec_test.go
src/text/template/funcs.go

index 6f40d80635fd0c691e6d6bf2291a7ccedeaf6f17..648ad8ff03d269f7145e419c92266c8e26a40729 100644 (file)
@@ -1279,6 +1279,7 @@ func TestBadFuncNames(t *testing.T) {
 }
 
 func testBadFuncName(name string, t *testing.T) {
+       t.Helper()
        defer func() {
                recover()
        }()
index abddfa1141b1f60edb633b799caddf51dd9e6784..31fe77a327dafad0036047c2970253ba462c6616 100644 (file)
@@ -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 {