GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Keep empty values in the middle and at the start of list.comma() by MahinAnowar · Pull Request #2134 · postcss/postcss

Conversation

@MahinAnowar

@MahinAnowar MahinAnowar commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

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:

list.comma(',,')    // ['']            expected ['', '', '']
list.comma(', b')   // ['b']           expected ['', 'b']
list.comma('a,, b') // ['a', 'b']      expected ['a', '', 'b']
list.comma('a, b,') // ['a', 'b', '']  already correct

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:

list.comma('a,,b')  // ['a', 'b']
list.comma('a, ,b') // ['a', '', 'b']

Rule#selectors reads through list.comma, so this loses a selector:

let rule = postcss.parse('a,,b{}').first
rule.selectors        // ['a', 'b']
rule.selectors = rule.selectors
rule.toString()       // 'a,b{}'

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 by last. The first and middle ones were still being dropped.

The change

One condition. last already marks the separator as significant — comma() passes it and space() 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.ts and two in test/rule.test.ts, covering the leading and middle positions and the spacing inconsistency. All six fail on main and 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:lint and pnpm test:types are clean.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@MahinAnowar
Keep empty values in the middle and at the start of list.comma()
38dffde
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().
@ai
ai merged commit 27c8be3 into postcss:main Aug 14, 2026
10 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@ai

ai commented Aug 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Thanks. I hope it would not break something

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MahinAnowar MahinAnowar mentioned this pull request Aug 19, 2026
Drop whitespace-only values from list.space() #2141
Merged
@00200200 00200200 mentioned this pull request Sep 29, 2026
Do not split list.comma() and list.space() on separators inside comments #2162
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@MahinAnowar @ai
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.