commit adf405496ea36f917709e5d58ba79bebcd3a0fa7
parent d9bc233f1f38df022864e0700a0514edf89b12d0
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date: Sun, 10 Jul 2016 15:10:22 +0200
Fix humanize when string is empty
Fixes #2272
Diffstat:
2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go
@@ -1703,6 +1703,11 @@ func humanize(in interface{}) (string, error) {
if err != nil {
return "", err
}
+
+ if word == "" {
+ return "", nil
+ }
+
return inflect.Humanize(word), nil
}
diff --git a/tpl/template_funcs_test.go b/tpl/template_funcs_test.go
@@ -1805,8 +1805,11 @@ func TestInflect(t *testing.T) {
expected string
}{
{humanize, "MyCamel", "My camel"},
+ {humanize, "", ""},
{pluralize, "cat", "cats"},
+ {pluralize, "", ""},
{singularize, "cats", "cat"},
+ {singularize, "", ""},
} {
result, err := this.inflectFunc(this.in)