Skip to content

Commit

Permalink
[Php70] Handle crash on EregToPregMatchRector (#2460)
Browse files Browse the repository at this point in the history
* Add fixture 5 to `ereg to preg match`

* Closes #2459

Co-authored-by: Thibault <thibault.andreis@gmail.com>
  • Loading branch information
samsonasik and ThibaultAndreis committed Jun 9, 2022
1 parent f2300ba commit eaea281
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Rector\Tests\Php70\Rector\FuncCall\EregToPregMatchRector\Fixture;

function eregToPregMatch5()
{
ereg_replace('[^0-9.-]', ' ', 'le 09.78-95 65/02');

}

?>
-----
<?php

namespace Rector\Tests\Php70\Rector\FuncCall\EregToPregMatchRector\Fixture;

function eregToPregMatch5()
{
preg_replace('#[^0-9\.\-]#m', ' ', 'le 09.78-95 65/02');

}

?>
4 changes: 3 additions & 1 deletion rules/Php70/EregToPcreTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private function processSquareBracket(string $s, int $i, int $l, string $cls, bo

if ($i < $l && $s[$i] === '-') {
$b = $s[++$i];
++$i;

if ($b === ']') {
$cls .= $this->_ere2pcre_escape($a) . '\-';
break;
Expand All @@ -257,6 +257,8 @@ private function processSquareBracket(string $s, int $i, int $l, string $cls, bo
}

$cls .= $this->_ere2pcre_escape($a) . '-' . $this->_ere2pcre_escape($b);

++$i;
} else {
$cls .= $this->_ere2pcre_escape($a);
}
Expand Down

0 comments on commit eaea281

Please sign in to comment.