diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 085136f0e151..bad8b56f9ff3 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -246,7 +246,22 @@ private static function findClasses($path) } // strip heredocs/nowdocs - $contents = preg_replace('{<<<[ \t]*([\'"]?)(\w+)\\1(?:\r\n|\n|\r)(?:.*(?=[\r\n]+[ \t]*\\2))[\r\n]+[ \t]*\\2(?=\s*[;,.)])}s', 'null', $contents); + $contents = preg_replace('{ + # opening heredoc/nowdoc delimiter (word-chars) + <<<[ \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 \b)[^\r\n]*+ + # end of line(s) + [\r\n]++ + )* + # end delimiter + [\t ]*+ \\2 (?=\b) + }xu', 'null', $contents); + // strip strings $contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents); // strip leading non-php code if needed diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index 261fb7cede6e..d367d72e0f3f 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -55,6 +55,9 @@ public function getTestCreateMapTests() 'Foo\\LargeGap' => realpath(__DIR__) . '/Fixtures/classmap/LargeGap.php', 'Foo\\MissingSpace' => realpath(__DIR__) . '/Fixtures/classmap/MissingSpace.php', 'Foo\\StripNoise' => realpath(__DIR__) . '/Fixtures/classmap/StripNoise.php', + 'Foo\\First' => realpath(__DIR__) . '/Fixtures/classmap/StripNoise.php', + 'Foo\\Second' => realpath(__DIR__) . '/Fixtures/classmap/StripNoise.php', + 'Foo\\Third' => realpath(__DIR__) . '/Fixtures/classmap/StripNoise.php', 'Foo\\SlashedA' => realpath(__DIR__) . '/Fixtures/classmap/BackslashLineEndingString.php', 'Foo\\SlashedB' => realpath(__DIR__) . '/Fixtures/classmap/BackslashLineEndingString.php', 'Unicode\\↑\\↑' => realpath(__DIR__) . '/Fixtures/classmap/Unicode.php', diff --git a/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php b/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php index 02da0a6c435c..caa50e41d42a 100644 --- a/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php +++ b/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php @@ -19,8 +19,14 @@ class FailHeredocWhitespace } WHITESPACE . <<< MARKERINTEXT In PHP < 7.3, the docblock marker could occur in the text as long as it did not occur at the very start of the line. +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 +{ +} Look at my driver's license, expires 1987. Look at my birthday, for crying out load I haven't even been born yet. And, look at this picture, my brother, my sister, and me. Look at the sweatshirt, Doc, class of 1984. Why do you keep following me around? Hey beat it, spook, this don't concern you. MARKERINTEXT . <<<"DOUBLEQUOTES" class FailHeredocDoubleQuotes @@ -89,4 +95,55 @@ public function test_simple_string() { return 'class FailSimpleString {}'; } + + public function test_unicode_heredoc() + { + return array(1, 2, <<<öéçив必 + class FailUnicode + { + } + öéçив必, 3, 4); + } + + public function test_wrapped_in_curly_brackets() + { + return ${<<