Skip to content

Commit

Permalink
Fix humanize when string is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
bep authored and tychoish committed Aug 13, 2017
1 parent 715a104 commit b027295
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tpl/template_funcs.go
Expand Up @@ -1703,6 +1703,11 @@ func humanize(in interface{}) (string, error) {
if err != nil {
return "", err
}

if word == "" {
return "", nil
}

return inflect.Humanize(word), nil
}

Expand Down
3 changes: 3 additions & 0 deletions tpl/template_funcs_test.go
Expand Up @@ -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)
Expand Down

0 comments on commit b027295

Please sign in to comment.