Skip to content

Fix container --label rejecting values that contain "="#1978

Open
OrtegaMatias wants to merge 1 commit into
apple:mainfrom
OrtegaMatias:fix/labels-value-with-equals
Open

Fix container --label rejecting values that contain "="#1978
OrtegaMatias wants to merge 1 commit into
apple:mainfrom
OrtegaMatias:fix/labels-value-with-equals

Conversation

@OrtegaMatias

Copy link
Copy Markdown

Type of Change

  • Bug fix

Motivation and Context

container run --label KEY=VALUE rejected any label whose value contained a =, failing with invalid label format — even though such values are valid and common (a reverse-proxy router rule, a nested key=value config, a URL with a query string). docker run --label splits the label on the first = only.

Fixes #1977.

Description

Parser.labels split each entry with split(separator: "=", maxSplits: 2) and only handled 1 or 2 parts, so a value containing = produced 3+ parts and hit the throwing default branch. Changed it to maxSplits: 1 (split on the first = only) — a label key cannot contain =, but the value may. This matches how the env-file parser already handles values (URL=https://foo.bar?baz=woo) and docker run --label.

Testing

Added testLabelsValueWithEquals to ParserTest.swift, covering a plain value, a value with one =, a value with several =, and a key with no value.

Transparency note: I could not run the in-repo test suite locally — this machine only has an Xcode 27 beta toolchain (which fails building a transitive dependency under strict concurrency) and the Command Line Tools, which lack the test frameworks. I confirmed the change compiles as part of the ContainerAPIClient target and reproduced the fix against the cases above. CI runs the added test.

`Parser.labels` split each `--label KEY=VALUE` entry on every '='
(`maxSplits: 2`) and rejected anything producing more than two parts, so
a label whose value contained '=' — a common shape, e.g. a reverse-proxy
router rule or a nested key=value config — failed with "invalid label
format" even though such values are valid.

Split on the first '=' only, matching how env values are already parsed
(see `envFile`) and `docker run --label`. `container run --label
config=key=value` now works.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container run --label rejects a label whose value contains "="

1 participant