Keep empty values in the middle and at the start of list.comma() - #2134
Merged
Conversation
split() only pushed an item at a separator when it had collected some
text, so an empty value was dropped unless it happened to be the last
one. list.comma(',,') returned [''] instead of ['', '', ''].
Whitespace hid the inconsistency: 'a, ,b' collects ' ', which is not
empty, so it survives and is then trimmed to ''. That makes the result
depend on the spacing rather than the number of commas:
list.comma('a,,b') // ['a', 'b']
list.comma('a, ,b') // ['a', '', 'b']
Rule#selectors reads through list.comma, so 'a,,b' reported two
selectors and assigning them back rewrote the rule as 'a,b'.
The `last` flag already marks the separator as significant, which is
what comma() passes and space() does not, so it is the right condition
here too. Runs of whitespace still collapse for space().
Member
|
Thanks. I hope it would not break something |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
list.split()only pushed an item when it had collected some text, so an empty value was dropped unless it happened to be the last one:Whitespace hides it.
'a, ,b'collects' 'between the commas, which is not empty, so it survives and is then trimmed to''. The result ends up depending on the spacing rather than on the number of commas:Rule#selectorsreads throughlist.comma, so this loses a selector:This is the same thing #2129 fixed for
'', just in the other positions — that PR made the empty value survive when it is the whole string, and the trailing empty was already handled bylast. The first and middle ones were still being dropped.The change
One condition.
lastalready marks the separator as significant —comma()passes it andspace()does not — so it is the right thing to check here too:if (split) { - if (current !== '') array.push(current.trim()) + if (last || current !== '') array.push(current.trim())space()is unchanged, so runs of whitespace still collapse rather than producing empty items. I added a test pinning that down as well, since it is the behaviour this condition protects.Tests
Four cases in
test/list.test.tsand two intest/rule.test.ts, covering the leading and middle positions and the spacing inconsistency. All six fail onmainand pass with the change. Full suite is 693 passing; the 686 that existed before are untouched, so nothing was relying on the empty values being dropped.pnpm test:lintandpnpm test:typesare clean.