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
4 changes: 3 additions & 1 deletion Sources/Services/ContainerAPIService/Client/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ 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, so a value may itself contain `=`
// (e.g. `--label 'rule=Host(`ex.com`)'`), matching `docker run --label`.
let parts = label.split(separator: "=", maxSplits: 1)
switch parts.count {
case 1:
result[String(parts[0])] = ""
Expand Down
16 changes: 16 additions & 0 deletions Tests/ContainerAPIClientTests/ParserTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,22 @@ struct ParserTest {
#expect(result["key99"] == "value99")
}

@Test("label value may contain '=' (split on first '=' only)")
func testLabelValueContainingEquals() throws {
let result = try Parser.labels([
"config=key=value",
"traefik.http.routers.x.rule=Host(`ex.com`)",
"plain=value",
"novalue",
"emptyvalue=",
])
#expect(result["config"] == "key=value")
#expect(result["traefik.http.routers.x.rule"] == "Host(`ex.com`)")
#expect(result["plain"] == "value")
#expect(result["novalue"] == "")
#expect(result["emptyvalue"] == "")
}

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