{"record":{"id":"f34322be98d9ab6e","repo":"docker/cli","slug":"label-s-contains-whitespaces","errorCode":null,"errorMessage":"label '%s' contains whitespaces","messagePattern":"label '(.+?)' contains whitespaces","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/opts.go","lineNumber":246,"sourceCode":"// ValidateLabel validates that the specified string is a valid label, and returns it.\n//\n// Labels are in the form of key=value; key must be a non-empty string, and not\n// contain whitespaces. A value is optional (defaults to an empty string if omitted).\n//\n// Leading whitespace is removed during validation but values are kept as-is\n// otherwise, so any string value is accepted for both, which includes whitespace\n// (for values) and quotes (surrounding, or embedded in key or value).\n//\n// TODO discuss if quotes (and other special characters) should be valid or invalid for keys\n// TODO discuss if leading/trailing whitespace in keys should be preserved (and valid)\nfunc ValidateLabel(value string) (string, error) {\n\tkey, _, _ := strings.Cut(value, \"=\")\n\tkey = strings.TrimLeft(key, whiteSpaces)\n\tif key == \"\" {\n\t\treturn \"\", fmt.Errorf(\"invalid label '%s': empty name\", value)\n\t}\n\tif strings.ContainsAny(key, whiteSpaces) {\n\t\treturn \"\", fmt.Errorf(\"label '%s' contains whitespaces\", key)\n\t}\n\treturn value, nil\n}\n\n// ValidateSysctl validates a sysctl and returns it.\nfunc ValidateSysctl(val string) (string, error) {\n\tvalidSysctlMap := map[string]bool{\n\t\t\"kernel.msgmax\":          true,\n\t\t\"kernel.msgmnb\":          true,\n\t\t\"kernel.msgmni\":          true,\n\t\t\"kernel.sem\":             true,\n\t\t\"kernel.shmall\":          true,\n\t\t\"kernel.shmmax\":          true,\n\t\t\"kernel.shmmni\":          true,\n\t\t\"kernel.shm_rmid_forced\": true,\n\t}\n\tvalidSysctlPrefixes := []string{\n\t\t\"net.\",","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/opts.go#L228-L264","documentation":"Thrown by ValidateLabel (opts.go:246) when the label key (after left-trimming whitespace) still contains a space or tab. Docker label keys must not contain whitespace so they can be parsed and indexed unambiguously. Only leading whitespace is stripped; internal/embedded whitespace in the key is invalid.","triggerScenarios":"Calling ValidateLabel with a key containing a space or tab, e.g. `my label=value`, `a\tb=x`, or `com example.foo=1`. After TrimLeft the first whitespace is gone but internal spaces remain, so ContainsAny against ` \\t` at line 245 returns true.","commonSituations":"Unquoted CLI arguments split by the shell (`--label com example.foo=1`), keys copied from a table/spreadsheet with spaces, tab characters from copy-paste, or a missing '=' making a multi-word phrase parse as the key.","solutions":["Remove all spaces and tabs from the label key; use dots, hyphens, or underscores as separators.","Quote the argument so the shell treats it as one token: `--label \"com.example.foo=1\"`.","If the space was meant to separate multiple labels, pass `--label` multiple times instead.","Run the key through a pre-check: `if strings.ContainsAny(key, \" \\t\") { ... }`."],"exampleFix":"// before\n--label com example team=payments\n// after\n--label com.example.team=payments","handlingStrategy":"validation","validationCode":"// Reject label keys containing whitespace before submission.\nkey, _, _ := strings.Cut(label, \"=\")\nif strings.ContainsAny(strings.TrimLeft(key, \" \\t\"), \" \\t\") {\n    return fmt.Errorf(\"label key %q contains whitespace\", key)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use dots/hyphens in keys, never spaces.","Quote the whole `key=value` argument in the shell.","Pass multiple labels via repeated --label, not a space-separated string.","Reject tabs copied from spreadsheets."],"tags":["docker","labels","validation","cli","whitespace"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}