Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/Services/ContainerAPIService/Client/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ public struct Parser {
if label.isEmpty {
throw ContainerizationError(.invalidArgument, message: "label cannot be an empty string")
}
let parts = label.split(separator: "=", maxSplits: 2)
// Split on the first '=' only: a label value may itself contain
// '=' (e.g. `--label rule=Host(`x`)&&Path(`/`)` or
// `--label config=key=value`), matching `docker run --label`.
let parts = label.split(separator: "=", maxSplits: 1)
switch parts.count {
case 1:
result[String(parts[0])] = ""
Expand Down
17 changes: 17 additions & 0 deletions Tests/ContainerAPIClientTests/ParserTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,23 @@ struct ParserTest {
#expect(result["key99"] == "value99")
}

@Test("labels preserve '=' characters in the value")
func testLabelsValueWithEquals() throws {
// Regression: a label whose value contained '=' (a common shape,
// e.g. router rules or nested key=value config) was rejected as an
// "invalid label format" because the entry was split on every '='.
let result = try Parser.labels([
"plain=value",
"config=key=value",
"expr=a=b=c",
"flag",
])
#expect(result["plain"] == "value")
#expect(result["config"] == "key=value")
#expect(result["expr"] == "a=b=c")
#expect(result["flag"] == "")
}

@Test("resolve with large input preserves all entries")
func testParseKeyValuePairsLargeInput() {
let pairs = (0..<100).map { "key\($0)=value\($0)" }
Expand Down