Skip to content

[BUGFIX] Allow comma in selectors #1293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Please also have a look at our

### Fixed

- Allow comma in selectors (e.g. `:not(html, body)`) (#1293)
- Insert `Rule` before sibling even with different property name
(in `RuleSet::addRule()`) (#1270)
- Ensure `RuleSet::addRule()` sets non-negative column number when sibling
Expand Down
6 changes: 3 additions & 3 deletions src/Property/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class Selector implements Renderable
public const SELECTOR_VALIDATION_RX = '/
^(
(?:
[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*="\'~\\[\\]()\\-\\s\\.:#+>]* # any sequence of valid unescaped characters
(?:\\\\.)? # a single escaped character
(?:([\'"]).*?(?<!\\\\)\\2)? # a quoted text like [id="example"]
[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*="\'~\\[\\]()\\-\\s\\.:#+>,]* # any sequence of valid unescaped characters
(?:\\\\.)? # a single escaped character
(?:([\'"]).*?(?<!\\\\)\\2)? # a quoted text like [id="example"]
)*
)$
/ux';
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/Property/SelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public static function provideSelectorsAndSpecificities(): array
'class with pseudo-selector' => ['.help:hover', 20],
'ID' => ['#file', 100],
'ID and descendant class' => ['#test .help', 110],
'`not`' => [':not(#your-mug)', 100],
// TODO, broken: The specificity should be the highest of the `:not` arguments, not the sum.
'`not` with multiple arguments' => [':not(#your-mug, .their-mug)', 110],
];
}

Expand Down