Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Drop whitespace-only values from list.space() - #2141

Merged
ai merged 1 commit into
postcss:mainfrom
MahinAnowar:fix/list-space-empty-values
Aug 19, 2026
Merged

Drop whitespace-only values from list.space()#2141
ai merged 1 commit into
postcss:mainfrom
MahinAnowar:fix/list-space-empty-values

Conversation

@MahinAnowar

Copy link
Copy Markdown
Contributor

list.space() can return an empty string, which is never a real value.

list.space('\r')                    // ['']                  expected []
list.space('"a b"\r\n\r\n"c d"')    // ['"a b"', '', '"c d"'] expected ['"a b"', '"c d"']

list.split() checks current !== '' 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 then trim() turns it into '' on the way into the array.

space() splits on ' ', '\n' and '\t', so a \r is 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.

a {
  grid-template-areas:
    "a b"

    "c d";
}

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() passes last = true and short-circuits ahead of the emptiness check, so nothing about it changes, including list.comma('a,,b') and list.comma('a, ,b') still matching.

Three assertions added; all three fail on main and pass here. Full pnpm unit is green at 699 tests, plus eslint and check-dts.

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.
@ai
ai merged commit 3909f50 into postcss:main Aug 19, 2026
10 checks passed
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.

2 participants