[Bug]: `--label key=` and `--opt key=` keep the trailing "=" in the key name
- Dominant language
- Swift
- Stars
- 49.9k
- Forks
- 1.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 22
Description
### I have done the following
- [x] I have searched the existing issues
- [x] If possible, I've reproduced the issue using the 'main' branch of this project
### Steps to reproduce
Create a volume with a label that has an explicitly empty value:
```
container volume create --label owner= myvolume
container volume inspect myvolume
```
The stored label key is `owner=` rather than `owner`. The same applies to `container network create --label` and to `container volume create --opt`.
### Problem description
`Utility.parseKeyValuePairs` splits each argument on `=`:
https://github.com/apple/container/blob/main/Sources/Services/ContainerAPIService/Client/Utility.swift#L356
```swift
let components = pair.split(separator: "=", maxSplits: 1)
if components.count == 2 {
result[String(components[0])] = String(components[1])
} else {
result[pair] = ""
}
```
`String.split` omits empty subsequences by default, so a trailing `=` yields a single component:
```swift
"owner=".split(separator: "=", maxSplits: 1)
// ["owner"]
```
The count is 1 rather than 2, so the `else` branch runs and stores the entire unsplit argument, including the `=`, as the key.
The doc comment above the function states that a standalone key is treated as `key=`, which implies `owner` and `owner=` should both produce the key `owner` with an empty value. Passing `omittingEmptySubsequences: false` gives `["owner", ""]` and makes both spellings agree.
Affected call sites:
- `Sources/ContainerCommands/Volume/VolumeCreate.swift` (`--label`, `--opt`)
- `Sources/ContainerCommands/Network/NetworkCreate.swift` (`--label`, `--opt`)
### Environment
- OS: macOS 26.5.2 (25F84)
- Xcode: 26.6 (17F113)
- Container: main at 07ff3c0 (also present in 1.1.0)
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Contributor guide
Research direction
Start with Utility.parseKeyValuePairs in Sources/Services/ContainerAPIService/Client/Utility.swift, including its doc comment, then inspect the affected --label and --opt call sites in VolumeCreate.swift and NetworkCreate.swift. Reproduce the volume command from the issue and verify that both key spellings store the same key and empty value, including for networks and options.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100