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

[CodingStyle] Skip new line on ConsistentPregDelimiterRector #1506

Merged
merged 8 commits into from
Dec 16, 2021

Conversation

samsonasik
Copy link
Member

Given the following code:

        $content = 'some texte';
        $parts = preg_split("/(\r\n|\n|\r){2}/", $content);

currently produce:

         $content = 'some texte';
-        $parts = preg_split("/(\r\n|\n|\r){2}/", $content);
+        $parts = preg_split("#(
+|
){2}#", $content);

which should be fixed.

This PR try to fix it.

Fixes rectorphp/rector#6868

@samsonasik
Copy link
Member Author

It seems because of INNER_REGEX constant doesn't use u modifier:

private const INNER_REGEX = '#(?<content>.*?)(?<close>[imsxeADSUXJu]*)$#s';

however, changing to u modifier will break existing fixture UpdateMultilinePcreExtendedPattern

class UpdateMultilinePcreExtendedPattern
{
public function run()
{
$file = preg_replace('/^(
test
)/x', '', $file);
$file = preg_replace('#^(
test
)#x', '', $file);
}
}
?>

     public function run()
     {
-        $file = preg_replace('#^(
+        $file = preg_replace('/^(
             test
-        )#x', '', $file);
+        )/x', '', $file);
 
         $file = preg_replace('#^(
             test
-        )#x', '', $file);
+        )\\\\\\\\\\\\\\\\\#x', '', $file);

@samsonasik
Copy link
Member Author

samsonasik commented Dec 16, 2021

Fixed 🎉 , handled with compare PCRE_UTF8 (u) value with PCRE_DOTALL (s) value, if not equal, check if it has \r or \n

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@TomasVotruba
Copy link
Member

Thank you 👍

@TomasVotruba TomasVotruba merged commit 6bd25c8 into main Dec 16, 2021
@TomasVotruba TomasVotruba deleted the skip-new-line branch December 16, 2021 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConsistentPregDelimiterRector Break regex with carriage return
4 participants