Skip to content

Commit 2bfcd91

Browse files
fix preg_match() warning for most filter usecases
when a --filter option is provided and it starts with an invalid regex-delimiter, it will emit the following warning: Warning: preg_match(): Delimiter must not be alphanumeric, backslash, or NUL this is really cumbersome when xdebug.scream=true is in use. also while stepdebugging with phpstorm for example, this will spam the console output of phpstorm. we can and should prevent that most obvious case by just checking if the supplied filter starts with an alphanumeric character.
1 parent 7ac8b4e commit 2bfcd91

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Runner/Filter/NameFilterIterator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use function preg_match;
1515
use function sprintf;
1616
use function str_replace;
17+
use function substr;
1718
use Exception;
1819
use PHPUnit\Framework\SelfDescribing;
1920
use PHPUnit\Framework\Test;
@@ -77,7 +78,7 @@ public function accept(): bool
7778
*/
7879
private function setFilter(string $filter): void
7980
{
80-
if (@preg_match($filter, '') === false) {
81+
if (preg_match('/[a-zA-Z0-9]/', substr($filter, 0, 1)) === 1 || @preg_match($filter, '') === false) {
8182
// Handles:
8283
// * testAssertEqualsSucceeds#4
8384
// * testAssertEqualsSucceeds#4-8

0 commit comments

Comments
 (0)