Skip to content

Commit

Permalink
fix for panics when humanize called on whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
khayyamsaleem committed Sep 21, 2024
1 parent 6ae7779 commit 784c899
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 784c899

Please # to comment.