diff --git a/cmd/helpers.go b/cmd/helpers.go index 7176566a..5243af93 100644 --- a/cmd/helpers.go +++ b/cmd/helpers.go @@ -10,13 +10,11 @@ import ( "github.com/spf13/pflag" ) +var unsafeRegex = regexp.MustCompile(`[^0-9a-z-]`) + // makeSafe ensures that any string is dns safe func makeSafe(in string) string { - out := regexp.MustCompile(`[^0-9a-z-]`).ReplaceAllString( - strings.ToLower(in), - "$1-$2", - ) - return out + return unsafeRegex.ReplaceAllString(strings.ToLower(in), "$1-$2") } // shortenEnvironment shortens the environment name down the same way that Lagoon does diff --git a/cmd/helpers_test.go b/cmd/helpers_test.go index 59524a25..4efaf97f 100644 --- a/cmd/helpers_test.go +++ b/cmd/helpers_test.go @@ -24,6 +24,11 @@ func Test_makeSafe(t *testing.T) { in: "Feature-Branch", want: "feature-branch", }, + { + name: "space in name", + in: "My Project", + want: "my-project", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {