MCPcopy Create free account
hub / github.com/ddev/ddev / sanitizeServiceName

Function sanitizeServiceName

pkg/dockerutil/docker_compose.go:417–431  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
417func 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}

Callers 1

PullImagesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected