Skip to content

Commit b0e3f08

Browse files
committed
Keep the trailing equals sign out of parsed key names
String.split omits empty subsequences by default, so an argument ending in "=" produced a single component. parseKeyValuePairs treated that as a standalone key and stored the whole unsplit argument, leaving the equals sign in the key name: "owner=" became the key "owner=" rather than "owner" with an empty value. The function's documentation states that a standalone key is treated as "key=", so both spellings should produce the same key. Keeping empty subsequences makes them agree. This affects --label and --opt on `container volume create` and `container network create`. Fixes #2013
1 parent cec124f commit b0e3f08

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Sources/Services/ContainerAPIService/Client/Utility.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ public struct Utility {
356356
public static func parseKeyValuePairs(_ pairs: [String]) -> [String: String] {
357357
var result: [String: String] = Dictionary(minimumCapacity: pairs.count)
358358
for pair in pairs {
359-
let components = pair.split(separator: "=", maxSplits: 1)
359+
let components = pair.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false)
360360
if components.count == 2 {
361361
result[String(components[0])] = String(components[1])
362362
} else {

Tests/ContainerAPIClientTests/UtilityTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ struct UtilityTests {
3838
#expect(result["standalone"] == "")
3939
}
4040

41+
@Test("Parse key with an explicitly empty value")
42+
func testKeyWithEmptyValue() {
43+
let result = Utility.parseKeyValuePairs(["owner="])
44+
45+
#expect(result["owner"] == "")
46+
#expect(result["owner="] == nil)
47+
}
48+
4149
@Test("Parse empty input")
4250
func testEmptyInput() {
4351
let result = Utility.parseKeyValuePairs([])

0 commit comments

Comments
 (0)