From adf405496ea36f917709e5d58ba79bebcd3a0fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 10 Jul 2016 15:10:22 +0200 Subject: [PATCH] Fix humanize when string is empty Fixes #2272 --- tpl/template_funcs.go | 5 +++++ tpl/template_funcs_test.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go index ea1ce8a51..b34300ab2 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 32e6e50f5..f0d123c0f 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)