Fix humanize when string is empty

Fixes #2272
This commit is contained in:
Bjørn Erik Pedersen 2016-07-10 15:10:22 +02:00
parent d9bc233f1f
commit adf405496e
2 changed files with 8 additions and 0 deletions

View file

@ -1703,6 +1703,11 @@ func humanize(in interface{}) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
if word == "" {
return "", nil
}
return inflect.Humanize(word), nil return inflect.Humanize(word), nil
} }

View file

@ -1805,8 +1805,11 @@ func TestInflect(t *testing.T) {
expected string expected string
}{ }{
{humanize, "MyCamel", "My camel"}, {humanize, "MyCamel", "My camel"},
{humanize, "", ""},
{pluralize, "cat", "cats"}, {pluralize, "cat", "cats"},
{pluralize, "", ""},
{singularize, "cats", "cat"}, {singularize, "cats", "cat"},
{singularize, "", ""},
} { } {
result, err := this.inflectFunc(this.in) result, err := this.inflectFunc(this.in)