Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Php55] Handle crash on ([[:upper:]]+) regex on PregReplaceEModifierRector #3037

Merged
merged 6 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won’t this not handle (…)e now?

Copy link
Member Author

@samsonasik samsonasik Nov 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seems require separate PR as the modifer can not only e:

echo preg_replace('{[[:upper:]]+}se', '_$0', 'FOO');

which seems needs extra check with e modifier which the change must only remove the e, to be:

echo preg_replace('{[[:upper:]]+}s', '_$0', 'FOO');

Also possibly other use cases for that.

Feel free to provide a different PR for solution for that if you found a solution first for that.

}

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

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