MCPcopy Create free account
hub / github.com/docker/cli / ValidateLabel

Function ValidateLabel

opts/opts.go:239–249  ·  view source on GitHub ↗

ValidateLabel validates that the specified string is a valid label, and returns it. Labels are in the form of key=value; key must be a non-empty string, and not contain whitespaces. A value is optional (defaults to an empty string if omitted). Leading whitespace is removed during validation but va

(value string)

Source from the content-addressed store, hash-verified

237// TODO discuss if quotes (and other special characters) should be valid or invalid for keys
238// TODO discuss if leading/trailing whitespace in keys should be preserved (and valid)
239func ValidateLabel(value string) (string, error) {
240 key, _, _ := strings.Cut(value, "=")
241 key = strings.TrimLeft(key, whiteSpaces)
242 if key == "" {
243 return "", fmt.Errorf("invalid label '%s': empty name", value)
244 }
245 if strings.ContainsAny(key, whiteSpaces) {
246 return "", fmt.Errorf("label '%s' contains whitespaces", key)
247 }
248 return value, nil
249}
250
251// ValidateSysctl validates a sysctl and returns it.
252func ValidateSysctl(val string) (string, error) {

Callers 1

TestValidateLabelFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestValidateLabelFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…