sanitizeServiceName sanitizes a string to be a valid Docker Compose service name by replacing any characters that don't match [a-zA-Z0-9._-] with hyphens See https://github.com/compose-spec/compose-go/blob/main/schema/compose-spec.json for allowed pattern
(input string)
| 415 | // by replacing any characters that don't match [a-zA-Z0-9._-] with hyphens |
| 416 | // See https://github.com/compose-spec/compose-go/blob/main/schema/compose-spec.json for allowed pattern |
| 417 | func sanitizeServiceName(input string) string { |
| 418 | if input == "" { |
| 419 | return "" |
| 420 | } |
| 421 | |
| 422 | invalidChars := regexp.MustCompile(`[^a-zA-Z0-9._-]`) |
| 423 | sanitized := invalidChars.ReplaceAllString(input, "-") |
| 424 | |
| 425 | multipleHyphens := regexp.MustCompile(`-+`) |
| 426 | sanitized = multipleHyphens.ReplaceAllString(sanitized, "-") |
| 427 | |
| 428 | sanitized = strings.Trim(sanitized, "-") |
| 429 | |
| 430 | return sanitized |
| 431 | } |