Skip to content

Commit

Permalink
Sanitize context name specifically without reusing path name sanitizing
Browse files Browse the repository at this point in the history
  • Loading branch information
silphid committed Jun 9, 2021
1 parent 8746585 commit b9c9207
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/internal/yey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "-")
Expand All @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/yey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit b9c9207

Please sign in to comment.