From: Bjørn Erik Pedersen Date: Sun, 10 Jul 2016 13:10:22 +0000 (+0200) Subject: Fix humanize when string is empty X-Git-Tag: v0.17~244 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=adf405496ea36f917709e5d58ba79bebcd3a0fa7;p=brevno-suite%2Fhugo Fix humanize when string is empty Fixes #2272 --- diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go index ea1ce8a5..b34300ab 100644 --- 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 index 32e6e50f..f0d123c0 100644 --- 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)