Skip to content

Commit d281a56

Browse files
committed
[BUGFIX] Allow selector combinators in pseudo-class functions
The bug was introduced by #1496 and related changes that split selector representation and parsing into compound selectors and combinators. Addresses some of the issues in #1533.
1 parent 34ba5d4 commit d281a56

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Please also have a look at our
2727
`getPropertyName()` (#1506)
2828
- `Selector` is now represented as a sequence of `Selector\Component` objects
2929
which can be accessed via `getComponents()`, manipulated individually, or set
30-
via `setComponents()` (#1478, #1486, #1487, #1488, #1494, #1496)
30+
via `setComponents()` (#1478, #1486, #1487, #1488, #1494, #1496, #1537)
3131
- `Selector::setSelector()` and `Selector` constructor will now throw exception
3232
upon provision of an invalid selectior (#1498, #1502)
3333
- Clean up extra whitespace in CSS selector (#1398)

src/Property/Selector/CompoundSelector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CompoundSelector implements Component
4646
(?:
4747
(?:
4848
# any sequence of valid unescaped characters, except quotes
49-
[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*=\\[\\]()\\-\\.:#,\\s]++
49+
[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*~=\\[\\]()\\-\\s\\.:#+>,]++
5050
|
5151
# one or more escaped characters
5252
(?:\\\\.)++

tests/Unit/Property/Selector/CompoundSelectorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ public static function provideCompoundSelectorAndSpecificity(): array
5757
'`not` with multiple arguments' => [':not(#your-mug, .their-mug)', 110],
5858
'attribute with `"`' => ['[alt="{}()[]\\"\',"]', 10],
5959
'attribute with `\'`' => ['[alt=\'{}()[]"\\\',\']', 10],
60+
// TODO, broken: specificity should be 11, but the calculator is treating the `n` as a type selector.
61+
'nth-last-child' => ['li:nth-last-child(2n+3)', 12],
62+
// TODO, maybe broken: specificity should probably be 2 (1 for `p` and 1 for `span`).
63+
'`not` with descendent combinator' => [':not(p span)', 1],
64+
// TODO, maybe broken: specificity should probably be 2 (1 for `p` and 1 for `span`).
65+
'`not` with child combinator' => [':not(p > span)', 1],
66+
// TODO, maybe broken: specificity should probably be 2 (1 for `h1` and 1 for `p`).
67+
'`not` with next-sibling combinator' => [':not(h1 + p)', 1],
68+
// TODO, maybe broken: specificity should probably be 2 (1 for `h1` and 1 for `p`).
69+
'`not` with subsequent-sibling combinator' => [':not(h1 ~ p)', 1],
6070
];
6171
}
6272

0 commit comments

Comments
 (0)