Skip to content

Do not split list.comma() and list.space() on separators inside comments - #2162

Merged
ai merged 1 commit into
postcss:mainfrom
00200200:fix-list-split-comments
Sep 29, 2026
Merged

ai merged 1 commit into
postcss:mainfrom
00200200:fix-list-split-comments

Conversation

@00200200

Copy link
Copy Markdown
Contributor

Fixes #2161.

list.split() already ignores separators inside quotes and functions, and it already treats \\, / \\ as escaped. It still walks into /* … */ comments, so a comma or space in a comment is treated as a real separator — including parentheses, which throws off the function-depth counter:

list.comma('a, /* , */ b')
// main:     ['a', '/*', '*/ b']
// expected: ['a', '/* , */ b']

list.space('f(/* ) */ a)')
// main:     ['f(/* )', '*/', 'a)']
// expected: ['f(/* ) */ a)']

Rule#selectors is list.comma(this.selector), so the same input splits a selector list:

new Rule({ selector: 'a /* , */, b' }).selectors
// main:     ['a /*', '*/', 'b']
// expected: ['a /* , */', 'b']

The parser strips comments from selectors and declaration values, so a parse() round-trip hides this. The helpers are documented as a safe split, and they are what plugins (and Rule#selectors) use on strings that may still contain comments.

The change

While scanning, treat /* … */ as a comment (same nesting rules as CSS: no nested comments, unclosed comments run to the end). Separators, quotes, and parentheses inside a comment are not significant. /* inside quotes or after \\ is unchanged.

comma() / space() emptiness behaviour from #2134 / #2141 is untouched.

Tests

New cases in test/list.test.ts (comma inside a comment, comment-only value, unclosed comment, quoted /*, escaped slash, spaces and parentheses inside comments) and one in test/rule.test.ts for Rule#selectors. All fail on main and pass here. list.js stays at 100% line/branch coverage.

Quotes, functions, and escapes were already skipped; commas and spaces
inside /* … */ still broke Rule#selectors and the public list helpers.
@ai
ai merged commit 7ac9026 into postcss:main Sep 29, 2026
10 checks passed
@ai

ai commented Sep 29, 2026

Copy link
Copy Markdown
Member

Thanks!

Do you need it right now? Or it is OK to wait another feature for release?

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.

list.comma() and list.space() split on separators inside CSS comments

2 participants