Skip to content

Commit

Permalink
Merge pull request #75 from khayyamsaleem/bugfix/74
Browse files Browse the repository at this point in the history
fix for panics when humanize called on whitespace
  • Loading branch information
paganotoni authored Sep 21, 2024
2 parents 6ae7779 + 784c899 commit cbe6b82
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions humanize.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
// Humanize returns first letter of sentence capitalized.
// Common acronyms are capitalized as well.
// Other capital letters in string are left as provided.
//
// employee_salary = Employee salary
// employee_id = employee ID
// employee_mobile_number = Employee mobile number
Expand All @@ -22,6 +23,10 @@ func (i Ident) Humanize() Ident {
return New("")
}

if strings.TrimSpace(i.Original) == "" {
return i
}

parts := xappend([]string{}, Titleize(i.Parts[0]))
if len(i.Parts) > 1 {
parts = xappend(parts, i.Parts[1:]...)
Expand Down
5 changes: 5 additions & 0 deletions humanize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func Test_Humanize(t *testing.T) {
{"first_Name", "First Name"},
{"firstName", "First Name"},
{"óbito", "Óbito"},
{" ", " "},
{"\n", "\n"},
{"\r", "\r"},
{"\t", "\t"},
{" \n\r\t", " \n\r\t"},
}

for _, tt := range table {
Expand Down

0 comments on commit cbe6b82

Please sign in to comment.