From 3fdcc573a6d4f8f8fa02a962c6a30da96836dee2 Mon Sep 17 00:00:00 2001 From: Thiago Gonzaga Date: Sat, 25 Jul 2026 16:18:05 -0300 Subject: [PATCH] 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 --- Sources/Services/ContainerAPIService/Client/Utility.swift | 2 +- Tests/ContainerAPIClientTests/UtilityTests.swift | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/Services/ContainerAPIService/Client/Utility.swift b/Sources/Services/ContainerAPIService/Client/Utility.swift index 4d0ba700a..3f44fbb20 100644 --- a/Sources/Services/ContainerAPIService/Client/Utility.swift +++ b/Sources/Services/ContainerAPIService/Client/Utility.swift @@ -348,7 +348,7 @@ public struct Utility { public static func parseKeyValuePairs(_ pairs: [String]) -> [String: String] { var result: [String: String] = Dictionary(minimumCapacity: pairs.count) for pair in pairs { - let components = pair.split(separator: "=", maxSplits: 1) + let components = pair.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false) if components.count == 2 { result[String(components[0])] = String(components[1]) } else { diff --git a/Tests/ContainerAPIClientTests/UtilityTests.swift b/Tests/ContainerAPIClientTests/UtilityTests.swift index 3a9b3a495..d1df02689 100644 --- a/Tests/ContainerAPIClientTests/UtilityTests.swift +++ b/Tests/ContainerAPIClientTests/UtilityTests.swift @@ -38,6 +38,14 @@ struct UtilityTests { #expect(result["standalone"] == "") } + @Test("Parse key with an explicitly empty value") + func testKeyWithEmptyValue() { + let result = Utility.parseKeyValuePairs(["owner="]) + + #expect(result["owner"] == "") + #expect(result["owner="] == nil) + } + @Test("Parse empty input") func testEmptyInput() { let result = Utility.parseKeyValuePairs([])