Skip to content

Commit

Permalink
[Php55] Handle crash on ([[:upper:]]+) regex on PregReplaceEModifierR…
Browse files Browse the repository at this point in the history
…ector (#3037)
  • Loading branch information
samsonasik committed Nov 7, 2022
1 parent 64d0a83 commit b7a6427
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\Php55\Rector\FuncCall\PregReplaceEModifierRector\Fixture;

class SkipNoModifier
{
public function run()
{
echo preg_replace('([[:upper:]]+)', '_$0', 'FOO');
}

public function run2()
{
echo preg_replace('{[[:upper:]]+}', '_$0', 'FOO');
}
}
4 changes: 4 additions & 0 deletions rules/Php55/RegexMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function resolvePatternExpressionWithoutEIfFound(Expr $expr): Concat|Stri
return null;
}

if (in_array($pattern[strlen($pattern) - 1], [')', '}', ']', '>'], true)) {
return null;
}

$patternWithoutE = $this->createPatternWithoutE($pattern, $delimiter, $modifiers);
return new String_($patternWithoutE);
}
Expand Down

0 comments on commit b7a6427

Please sign in to comment.