Skip to content

Commit

Permalink
fix: no panic after on defaultNamifier (#236)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Chen <[email protected]>
  • Loading branch information
nickchen and nginx-nickc authored Jun 20, 2024
1 parent b5810b7 commit ba075d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
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

0 comments on commit ba075d6

Please sign in to comment.