Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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

- Parse selector functions (like `:not`) with comma-separated arguments (#1292)
- Parse quoted attribute selector value containing comma (#1323)
- Allow comma in selectors (e.g. `:not(html, body)`) (#1293)
- Insert `Rule` before sibling even with different property name
Expand Down
18 changes: 16 additions & 2 deletions src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public static function parse(ParserState $parserState, ?CSSList $list = null): ?
$selectors = [];
$selectorParts = [];
$stringWrapperCharacter = null;
$functionNestingLevel = 0;
$consumedNextCharacter = false;
static $stopCharacters = ['{', '}', '\'', '"', ','];
static $stopCharacters = ['{', '}', '\'', '"', '(', ')', ','];
do {
if (!$consumedNextCharacter) {
$selectorParts[] = $parserState->consume(1);
Expand All @@ -64,8 +65,21 @@ public static function parse(ParserState $parserState, ?CSSList $list = null): ?
}
}
break;
case ',':
case '(':
if (!\is_string($stringWrapperCharacter)) {
++$functionNestingLevel;
}
break;
case ')':
if (!\is_string($stringWrapperCharacter)) {
if ($functionNestingLevel <= 0) {
throw new UnexpectedTokenException('anything but', ')');
Comment thread
oliverklee marked this conversation as resolved.
}
--$functionNestingLevel;
}
break;
case ',':
if (!\is_string($stringWrapperCharacter) && $functionNestingLevel === 0) {
$selectors[] = \implode('', $selectorParts);
$selectorParts = [];
$parserState->consume(1);
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/RuleSet/DeclarationBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static function provideSelector(): array
'pseudo-class' => [':hover'],
'type & pseudo-class' => ['a:hover'],
'`not`' => [':not(#your-mug)'],
'`not` with multiple arguments' => [':not(#your-mug, .their-mug)'],
'pseudo-element' => ['::before'],
'attribute with `"`' => ['[alt="{}()[]\\"\',"]'],
'attribute with `\'`' => ['[alt=\'{}()[]"\\\',\']'],
Expand Down