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

Function normalizeConstraint

pkg/ddevapp/utils.go:587–601  ·  view source on GitHub ↗

normalizeConstraint adds '-0' to version expressions that don't contain a prerelease identifier See https://github.com/Masterminds/semver#working-with-prerelease-versions

(constraint string)

Source from the content-addressed store, hash-verified

585// normalizeConstraint adds '-0' to version expressions that don't contain a prerelease identifier
586// See https://github.com/Masterminds/semver#working-with-prerelease-versions
587func normalizeConstraint(constraint string) string {
588 // remove all commas, so we can split by spaces
589 constraintNoCommas := strings.ReplaceAll(constraint, ",", " ")
590 // Split the constraint into tokens based on spaces
591 tokens := strings.Fields(constraintNoCommas)
592 for i, token := range tokens {
593 last := token[len(token)-1]
594 // If the token represents a version number (ends with a digit or is a wildcard)
595 // and doesn't contain a suffix '-0', append '-0'
596 if !strings.HasSuffix(token, "-0") && strings.Contains("0123456789xX*", string(last)) {
597 tokens[i] = token + "-0"
598 }
599 }
600 return strings.Join(tokens, " ")
601}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected