Skip to content

[CodingStyle] Skip new line on ConsistentPregDelimiterRector#1506

Merged
TomasVotruba merged 8 commits intomainfrom
skip-new-line
Dec 16, 2021
Merged

[CodingStyle] Skip new line on ConsistentPregDelimiterRector#1506
TomasVotruba merged 8 commits intomainfrom
skip-new-line

Conversation

@samsonasik
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

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

@TomasVotruba
Copy link
Copy Markdown
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