diff --git a/src/internal/yey.go b/src/internal/yey.go index 1305951..5455e77 100644 --- a/src/internal/yey.go +++ b/src/internal/yey.go @@ -27,12 +27,16 @@ func ContainerName(path string, context Context) string { return fmt.Sprintf( "%s-%s-%s", ContainerPathPrefix(path), - sanitize(context.Name), + sanitizeContextName(context.Name), hash(context.String()), ) } -func sanitize(value string) string { +func sanitizeContextName(value string) string { + return special.ReplaceAllString(value, "-") +} + +func sanitizePathName(value string) string { value = spaces.ReplaceAllString(value, "_") value = special.ReplaceAllString(value, "") value = dashes.ReplaceAllString(value, "-") @@ -50,7 +54,7 @@ func sanitize(value string) string { } func ContainerPathPrefix(path string) string { - pathBase := sanitize(filepath.Base(filepath.Dir(path))) + pathBase := sanitizePathName(filepath.Base(filepath.Dir(path))) if pathBase == "" { return fmt.Sprintf("yey-%s", hash(path)) } diff --git a/src/internal/yey_test.go b/src/internal/yey_test.go index 60ae555..3cb4471 100644 --- a/src/internal/yey_test.go +++ b/src/internal/yey_test.go @@ -47,7 +47,7 @@ func TestSanitizePathName(t *testing.T) { for _, tc := range testCases { t.Run(tc.Name, func(t *testing.T) { - actual := sanitize(tc.Value) + actual := sanitizePathName(tc.Value) if actual != tc.Expected { t.Fatalf("expected %s but got: %s", tc.Expected, actual) }