Skip to content

Split --label on the first '=' only so values may contain '='#1999

Open
chengboonrong wants to merge 1 commit into
apple:mainfrom
chengboonrong:fix/label-value-equals
Open

Split --label on the first '=' only so values may contain '='#1999
chengboonrong wants to merge 1 commit into
apple:mainfrom
chengboonrong:fix/label-value-equals

Conversation

@chengboonrong

Copy link
Copy Markdown

Summary

container run --label KEY=VALUE rejected any label whose value contained a
=:

$ container run --rm --label 'config=key=value' alpine true
Error: invalid label format config=key=value

This blocks common real-world values such as reverse-proxy router rules
(--label 'traefik.http.routers.x.rule=Host(ex.com)') and nested
key=value configuration.

Root cause

Parser.labels split each entry with split(separator: "=", maxSplits: 2) and
only handled 1 or 2 parts, throwing for anything else. A value containing a =
produces 3+ parts and hits the default (throw) branch.

Fix

Split on the first = only (maxSplits: 1), keeping everything after it as
the value. This matches docker run --label and the env-file parser already in
this same file (URL=https://foo.bar?baz=woo is accepted). Entries with no =
still map to an empty value; behavior for all previously-valid labels is
unchanged.

Tests

Adds a ParserTest case covering a value with =, a Traefik-style rule, a
plain key=value, a bare key, and an empty value. Verified locally:
swift build, swift format lint --strict, and the parser tests all pass.

Fixes #1977

🤖 Generated with Claude Code

@chengboonrong
chengboonrong force-pushed the fix/label-value-equals branch from e002029 to d235642 Compare July 23, 2026 13:25
`Parser.labels` split each entry with `split(separator: "=", maxSplits: 2)`
and only handled 1 or 2 parts, so any `--label KEY=VALUE` whose value
contained a `=` produced 3+ parts and was rejected with "invalid label
format". This blocked common values such as reverse-proxy router rules
(`traefik.http.routers.x.rule=Host(...)`) and nested `key=value` config.

Split on the first `=` only (`maxSplits: 1`), matching `docker run
--label` and the env-file parser in this same file. Everything after the
first `=` is kept verbatim as the value; entries without a `=` still map
to an empty value.

Fixes apple#1977

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Chris Cheng <chengchris8715@gmail.com>
@chengboonrong
chengboonrong force-pushed the fix/label-value-equals branch from d235642 to 77d2cd8 Compare July 23, 2026 13:38
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