From ed556cfaf32e1b2157cd768c34a89e4740036b60 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Fri, 19 Sep 2025 17:59:50 +0200 Subject: [PATCH] [BUGFIX] Use safe preg functions in `SpecificityCalculator` Part of #1168 --- CHANGELOG.md | 2 +- src/Property/Selector/SpecificityCalculator.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb49ebbd4..8978fbb71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ Please also have a look at our ### Fixed -- Use typesafe versions of PHP functions (#1379, #1380, #1382, #1383) +- Use typesafe versions of PHP functions (#1379, #1380, #1382, #1383, #1384) ### Documentation diff --git a/src/Property/Selector/SpecificityCalculator.php b/src/Property/Selector/SpecificityCalculator.php index 745f229d2..b2f1323e5 100644 --- a/src/Property/Selector/SpecificityCalculator.php +++ b/src/Property/Selector/SpecificityCalculator.php @@ -4,6 +4,8 @@ namespace Sabberworm\CSS\Property\Selector; +use function Safe\preg_match_all; + /** * Utility class to calculate the specificity of a CSS selector. * @@ -67,8 +69,8 @@ public static function calculate(string $selector): int /// @todo should exclude \# as well as "#" $matches = null; $b = \substr_count($selector, '#'); - $c = \preg_match_all(self::NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX, $selector, $matches); - $d = \preg_match_all(self::ELEMENTS_AND_PSEUDO_ELEMENTS_RX, $selector, $matches); + $c = preg_match_all(self::NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX, $selector, $matches); + $d = preg_match_all(self::ELEMENTS_AND_PSEUDO_ELEMENTS_RX, $selector, $matches); self::$cache[$selector] = ($a * 1000) + ($b * 100) + ($c * 10) + $d; }