Drop whitespace-only values from list.space() - #2141
Merged
Conversation
list.split() tested current for emptiness before trimming it, so a chunk made only of whitespace that is not one of the separators survived the check and was pushed as an empty string. Trimming first makes the emptiness check see the value that actually gets pushed.
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.space()can return an empty string, which is never a real value.list.split()checkscurrent !== ''before it trims, so the check is looking at a different string from the one it pushes. A chunk made only of whitespace that isn't one of the separators is not empty, so it passes the check, and thentrim()turns it into''on the way into the array.space()splits on' ','\n'and'\t', so a\ris exactly such a chunk. That makes the result depend on line endings: the same stylesheet gives different values on CRLF than it does on LF.Saved with LF,
list.space(decl.value)gives two values. Saved with CRLF, it gives three, and the middle one is empty.This is the other half of #2134. That one was about
comma()dropping empty values it should keep; the note there was that whitespace hides the problem because' 'survives the emptiness check and is trimmed afterwards. The same untrimmed check leaks a value here instead of dropping one, so trimming before the check settles both directions.comma()passeslast = trueand short-circuits ahead of the emptiness check, so nothing about it changes, includinglist.comma('a,,b')andlist.comma('a, ,b')still matching.Three assertions added; all three fail on
mainand pass here. Fullpnpm unitis green at 699 tests, plus eslint and check-dts.