From 12421dd6b7eeaa1cb9b62754ce84ff6e1de94441 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 28 Apr 2014 15:19:38 +0200 Subject: [PATCH] fixed class map generator when using a heredoc with spaces --- src/Composer/Autoload/ClassMapGenerator.php | 2 +- .../Autoload/Fixtures/classmap/StripNoise.php | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 5d939ffa9..924a930c7 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -119,7 +119,7 @@ class ClassMapGenerator } // strip heredocs/nowdocs - $contents = preg_replace('{<<<\'?(\w+)\'?(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)\\1(?=\r\n|\n|\r|;)}s', 'null', $contents); + $contents = preg_replace('{<<<\s*(\'?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)\\2(?=\r\n|\n|\r|;)}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 3fe5389be..4c344089b 100644 --- a/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php +++ b/tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php @@ -15,12 +15,30 @@ class Fail2 } A -. <<<'TEST' +. <<< AB class Fail3 { } -TEST; +AB +. <<<'TEST' +class Fail4 +{ + +} +TEST +. <<< 'ANOTHER' +class Fail5 +{ + +} +ANOTHER +. <<< 'ONEMORE' +class Fail6 +{ + +} +ONEMORE; } public function test2()