diff --git a/pkg/util/util.go b/pkg/util/util.go index 10beffd8..45d56631 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -219,13 +219,13 @@ func PrintDelimiterLine(delimiterChar string) { func SanitizeName(s string, maxLength int) string { reg := regexp.MustCompile("^[^a-zA-Z0-9]+") - processed := reg.ReplaceAllString(s, "") - excess := len(processed) - maxLength + excess := len(s) - maxLength + result := s if excess > 0 { - return processed[excess:] + result = s[excess:] } - return processed + return reg.ReplaceAllString(result, "") } func GetRandomPort() (int, error) { diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index 11bd3ff3..9de19a38 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -79,7 +79,7 @@ func TestSanitizeName(t *testing.T) { {"way-longer-than-max-length", 10, "max-length"}, {"one-shorter-than-max-length", len("one-shorter-than-max-length") + 1, "one-shorter-than-max-length"}, {"oone-longer-than-max-length", len("oone-longer-than-max-length") - 1, "one-longer-than-max-length"}, - {"-starts-with-invalid-char", 63, "starts-with-invalid-char"}, + {"foo-would-start-with-hyphen-after-trimming", len("foo-would-start-with-hyphen-after-trimming") - 3, "would-start-with-hyphen-after-trimming"}, } for index, testData := range testDataSlice {