Skip to content

Commit defd406

Browse files
staabmondrejmirtes
authored andcommitted
Fix preg_match() group containing start/end meta characters
1 parent 5dfc583 commit defd406

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Type/Regex/RegexGroupParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ private function isMaybeEmptyNode(TreeNode $node, string $patternModifiers, bool
527527
if ($literal !== '' && $literal !== '0') {
528528
$isNonFalsy = true;
529529
}
530-
return false;
530+
return $literal === '';
531531
}
532532

533533
foreach ($node->getChildren() as $child) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Bug12297;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function doFoo($s) {
8+
if (preg_match('/(^.+)/', $s, $matches) === 1) {
9+
assertType('non-empty-string', $matches[1]);
10+
}
11+
12+
if (preg_match('/(.+$)/', $s, $matches) === 1) {
13+
assertType('non-empty-string', $matches[1]);
14+
}
15+
16+
if (preg_match('/(^.+$)/', $s, $matches) === 1) {
17+
assertType('non-empty-string', $matches[1]);
18+
}
19+
}

0 commit comments

Comments
 (0)