mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
String.split omits final empty string(s) for trailing pattern
#338
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sin-ack on GitHub (Aug 18, 2025).
Reproduced in 0.29.0.
Reproducer:
Empty strings will be omitted from the end no matter how many times you repeat the pattern.
@StefMa commented on GitHub (Aug 18, 2025):
The issue occurs because the implementation of String.split in the codebase ultimately delegates to Java’s String.split method. By default, Java’s split omits trailing empty strings from the result. This is reflected in StringNodes.java, where the split method calls self.split(Pattern.quote(separator)), so when the separator appears at the end of the string or multiple times in succession, the resulting list omits empty strings at the end—matching the behavior you observed in your examples.
@bioball commented on GitHub (Aug 18, 2025):
I agree that the behavior seems incorrect. However, fixing this now would be a breaking change.
To get your expected behavior, you can use
splitLimitinstead. For example:@sin-ack commented on GitHub (Aug 18, 2025):
Thanks for the workaround!