Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Please also have a look at our

### Fixed

- Improve performance of selector validation
(avoiding silent PCRE catastrophic failure) (#1372)
- Use typesafe versions of PHP functions (#1368, #1370)

### Documentation
Expand Down
44 changes: 32 additions & 12 deletions src/Property/KeyframeSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,41 @@
class KeyframeSelector extends Selector
{
/**
* regexp for specificity calculations
* This differs from the parent class:
* - comma is not allowed unless escaped or quoted;
* - percentage value is allowed by itself.
*
* @var string
* @var non-empty-string
*
* @internal since 8.5.2
*/
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"]
)*
)|
(\\d+%) # keyframe animation progress percentage (e.g. 50%)
$
/ux';
^(
(?:
# any sequence of valid unescaped characters, except quotes
[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*=~\\[\\]()\\-\\s\\.:#+>]++
|
# one or more escaped characters
(?:\\\\.)++
|
# quoted text, like in `[id="example"]`
(?:
# opening quote
([\'"])
(?:
# sequence of characters except closing quote or backslash
(?:(?!\\g{-1}|\\\\).)++
|
# one or more escaped characters
(?:\\\\.)++
)*+ # zero or more times
# closing quote or end (unmatched quote is currently allowed)
(?:\\g{-1}|$)
)
)*+ # zero or more times
|
# keyframe animation progress percentage (e.g. 50%), untrimmed
\\s*+(\\d++%)\\s*+
)$
/ux';
}
29 changes: 22 additions & 7 deletions src/Property/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,34 @@
class Selector implements Renderable
{
/**
* regexp for specificity calculations
*
* @var string
* @var non-empty-string
*
* @internal since 8.5.2
*/
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"]
)*
# any sequence of valid unescaped characters, except quotes
[a-zA-Z0-9\\x{00A0}-\\x{FFFF}_^$|*=~\\[\\]()\\-\\s\\.:#+>,]++
|
# one or more escaped characters
(?:\\\\.)++
|
# quoted text, like in `[id="example"]`
(?:
# opening quote
([\'"])
(?:
# sequence of characters except closing quote or backslash
(?:(?!\\g{-1}|\\\\).)++
|
# one or more escaped characters
(?:\\\\.)++
)*+ # zero or more times
# closing quote or end (unmatched quote is currently allowed)
(?:\\g{-1}|$)
)
)*+ # zero or more times
)$
/ux';

Expand Down