Skip to content

Commit a72e71e

Browse files
authored
[BUGFIX] Use the safe regexp functions in Selector (#1371)
Part of #1168
1 parent 8263604 commit a72e71e

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

config/phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ parameters:
8484
count: 1
8585
path: ../tests/ParserTest.php
8686

87-
-
88-
message: '#^Parameter \#1 \$message of static method PHPUnit\\Framework\\Assert\:\:fail\(\) expects string, Exception given\.$#'
89-
identifier: argument.type
90-
count: 1
91-
path: ../tests/ParserTest.php
92-
9387
-
9488
message: '#^Parameter \#1 \$value of method Sabberworm\\CSS\\Rule\\Rule\:\:setValue\(\) expects Sabberworm\\CSS\\Value\\RuleValueList\|string\|null, Sabberworm\\CSS\\Value\\Size given\.$#'
9589
identifier: argument.type

src/Property/Selector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Sabberworm\CSS\Property\Selector\SpecificityCalculator;
99
use Sabberworm\CSS\Renderable;
1010

11+
use function Safe\preg_match;
12+
1113
/**
1214
* Class representing a single CSS selector. Selectors have to be split by the comma prior to being passed into this
1315
* class.
@@ -57,7 +59,7 @@ class Selector implements Renderable
5759
public static function isValid(string $selector): bool
5860
{
5961
// Note: We need to use `static::` here as the constant is overridden in the `KeyframeSelector` class.
60-
$numberOfMatches = \preg_match(static::SELECTOR_VALIDATION_RX, $selector);
62+
$numberOfMatches = preg_match(static::SELECTOR_VALIDATION_RX, $selector);
6163

6264
return $numberOfMatches === 1;
6365
}

tests/ParserTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,7 @@ public function files(): void
7373
continue;
7474
}
7575
$parser = new Parser(\file_get_contents($directory . '/' . $filename));
76-
try {
77-
self::assertNotEquals('', $parser->parse()->render());
78-
} catch (\Exception $e) {
79-
self::fail($e);
80-
}
76+
self::assertNotSame('', $parser->parse()->render());
8177
}
8278
\closedir($directoryHandle);
8379
}

0 commit comments

Comments
 (0)