Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for panics when humanize called on whitespace #75

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading