Skip to content

Commit b80d4b6

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. Fixes #1533
1 parent 17dd54a commit b80d4b6

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, #1536)
30+
via `setComponents()` (#1478, #1486, #1487, #1488, #1494, #1496, #1536, #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
@@ -48,7 +48,7 @@ class CompoundSelector implements Component
4848
(?:
4949
(?:
5050
# any sequence of valid unescaped characters, except quotes
51-
[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*~=\\[\\]()\\-\\.:#,\\s]++
51+
[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*=~\\[\\]()\\-\\s\\.:#+>,]++
5252
|
5353
# one or more escaped characters
5454
(?:\\\\.)++

tests/Unit/Property/Selector/CompoundSelectorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public static function provideCompoundSelectorAndSpecificity(): array
6868
'attribute with case insensitive modifier' => ['a[href*="insensitive" i]', 12],
6969
// TODO, broken: specificity should be 21, but the calculator doesn't realize the `.` is in a string.
7070
'multiple attributes' => ['a[href^="https://"][href$=".org"]', 31],
71+
// TODO, broken: specificity should be 11, but the calculator is treating the `n` as a type selector.
72+
'nth-last-child' => ['li:nth-last-child(2n+3)', 12],
73+
// TODO, maybe broken: specificity should probably be 2 (1 for `p` and 1 for `span`).
74+
'`not` with descendent combinator' => [':not(p span)', 1],
75+
// TODO, maybe broken: specificity should probably be 2 (1 for `p` and 1 for `span`).
76+
'`not` with child combinator' => [':not(p > span)', 1],
77+
// TODO, maybe broken: specificity should probably be 2 (1 for `h1` and 1 for `p`).
78+
'`not` with next-sibling combinator' => [':not(h1 + p)', 1],
79+
// TODO, maybe broken: specificity should probably be 2 (1 for `h1` and 1 for `p`).
80+
'`not` with subsequent-sibling combinator' => [':not(h1 ~ p)', 1],
7181
];
7282
}
7383

0 commit comments

Comments
 (0)