From 971528916b5c955066a7bc677d94032fd4c99298 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Wed, 3 Apr 2019 10:33:58 +0200 Subject: [PATCH] fix regex for heredoc/nowdoc * take into account relaxed changes introduced in php 7.3 * see: https://github.com/php/php-src/commit/4887357269107ed669463c4b95bd755fbbb52490 * allow " as well as ', which was introduced in php 5.3 closes #8080 --- src/Composer/Autoload/ClassMapGenerator.php | 2 +- .../Test/Autoload/Fixtures/classmap/StripNoise.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 5d937433b..f3245bca6 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -162,7 +162,7 @@ class ClassMapGenerator } // strip heredocs/nowdocs - $contents = preg_replace('{<<<\s*(\'?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)\\2(?=\r\n|\n|\r|;)}s', 'null', $contents); + $contents = preg_replace('{<<<\s*([\'"]?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r|\s*)\\2(?=\r\n|\n|\r|\s|;)}s', 'null', $contents); // strip strings $contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents); // strip leading non-php code if needed diff --git a/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php b/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php index 4c344089b..3806791e3 100644 --- a/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php +++ b/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php @@ -33,12 +33,18 @@ class Fail5 } ANOTHER -. <<< 'ONEMORE' +. <<< "ONEMORE" class Fail6 { } -ONEMORE; +ONEMORE +. <<