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: no panic after on defaultNamifier #236

Merged
merged 1 commit into from
Jun 20, 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
3 changes: 3 additions & 0 deletions pkg/utils/template/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func DefaultNamifier(sentence string) string {
// Remove leading numbers
re = regexp.MustCompile("^[0-9]+")
sentence = string(re.ReplaceAll([]byte(sentence), []byte("")))
if len(sentence) == 0 {
return sentence
}

// Upper first letter
sentence = strings.ToUpper(sentence[:1]) + sentence[1:]
Expand Down
4 changes: 4 additions & 0 deletions pkg/utils/template/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type namifyCases struct {
var namifyBaseCases = []namifyCases{
// Nothing
{In: "", Out: ""},
// new line
{In: "\n", Out: ""},
// just numbers
{In: "00", Out: ""},
// Remove leading digits
{In: "0name0", Out: "Name0"},
// Remove non alphanumerics
Expand Down