From d8054d1d2f2c55f26a032fd6c6b43c9b340bb5b8 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 29 Aug 2021 12:19:33 +0200 Subject: [PATCH] Add more possessive quantifiers, unicode flag and support for more post-heredoc syntax, fix test file syntax being invalid --- src/Composer/Autoload/ClassMapGenerator.php | 10 +++---- .../Autoload/Fixtures/classmap/StripNoise.php | 29 ++++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 2c46d000e..bad8b56f9 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -248,19 +248,19 @@ class ClassMapGenerator // strip heredocs/nowdocs $contents = preg_replace('{ # opening heredoc/nowdoc delimiter (word-chars) - <<<[ \t]*([\'"]?)(\w+)\\1 + <<<[ \t]*+([\'"]?)(\w++)\\1 # needs to be followed by a newline (?:\r\n|\n|\r) # the meat of it, matching line by line until end delimiter (?: # a valid line is optional white-space (possessive match) not followed by the end delimiter, then anything goes for the rest of the line - [\t ]*+(?!\\2 [\t \r\n]*[;,.)])[^\r\n]* + [\t ]*+(?!\\2 \b)[^\r\n]*+ # end of line(s) - [\r\n]+ + [\r\n]++ )* # end delimiter - [\t ]* \\2 (?=[\t \r\n]*[;,.)]) - }x', 'null', $contents); + [\t ]*+ \\2 (?=\b) + }xu', 'null', $contents); // strip strings $contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents); diff --git a/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php b/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php index c1d6c3df4..caa50e41d 100644 --- a/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php +++ b/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php @@ -23,7 +23,7 @@ class FailHeredocMarkerInText { } But, what are you blind McFly, it's there. How else do you explain that wreck out there? Doc, Doc. Oh, no. You're alive. Bullet proof vest, how did you know, I never got a chance to tell you. About all that talk about screwing up future events, the space time continuum. Okay, alright, I'll prove it to you. - MARKERINTEXT + . MARKERINTEXT class FailHeredocMarkerInText2 { } @@ -95,6 +95,33 @@ NOWDOCTABBED . <<<'NOWDOCPHP73' { return 'class FailSimpleString {}'; } + + public function test_unicode_heredoc() + { + return array(1, 2, <<<öéçив必 + class FailUnicode + { + } + öéçив必, 3, 4); + } + + public function test_wrapped_in_curly_brackets() + { + return ${<<