Skip to content

Conversation

@Adobels
Copy link
Contributor

@Adobels Adobels commented Dec 22, 2025

Motivation

Closes #122

Modifications

  • Set omittingEmptySubsequences to false in String.split(separator:omittingEmptySubsequences:) when decoding a string that represents Bool, Int, or Double arrays separated by commas in EnvironmentValuesProvider.
  • Update CLIArgumentParser.swift:125 to use split instead of components(separatedBy:), ensuring homogeneous usage of Swift’s splitting APIs.

Result

A string representing an array of values separated by "," will now emit empty values when two separators appear together while parsing EnvironmentValuesProvider dictionaries.
This results in treating an empty value as an empty string and, consequently, throwing an error when parsed by individual value decoders for Int, Double, and Bool.

The additional update enforces homogeneous API usage and favors Swift’s native split(separator:) method.

Test Plan

Add tests covering empty values in Int, Double, and Bool arrays.

@Adobels
Copy link
Contributor Author

Adobels commented Dec 22, 2025

What I found while working on the issue is that Swift’s native API is String.split(separator:), whereas components(separatedBy:) is an NSString-bridged method backed by UTF-16 storage. Swift’s String uses UTF-8-backed storage.

The preferred API is split(separator:), with omittingEmptySubsequences when needed.

In the project, CLIArgumentParser.swift:125 uses the NSString API. It would be worth converting this to String.split(separator:) and disallowing future use of NSString APIs. Due to bridging between the two types, it is easy to accidentally rely on NSString when working with String.

If needed, I will revert the commit: ae5cf01

@Adobels Adobels marked this pull request as ready for review December 22, 2025 10:20
@Adobels Adobels changed the title Update split method to keep empty substrings Update EnvironmentValueArrayDecoder to emit empty values when present Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EnvironmentVariablesProvider: split(separator:) leads to inconsistent boolean array decoding between whitespace-only and empty elements

1 participant