From 9588654ae3881f7f2270e7dd464568dc7d82b379 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 11 Aug 2021 21:08:38 +0200 Subject: [PATCH] ClassMapGenerator: add tests for "long heredoc" bug ... to proof the existence of the bug and demonstrate the effect. Note: in the test the backtrack limit is being lowered (and restored back to the default afterwards) to prevent the tests needing ridiculously huge test fixture files. --- .../Test/Autoload/ClassMapGeneratorTest.php | 19 + .../pcrebacktracelimit/StripNoise.php | 87 ++ .../pcrebacktracelimit/VeryLongHeredoc.php | 464 ++++++++ .../pcrebacktracelimit/VeryLongNowdoc.php | 327 ++++++ .../VeryLongPHP73Heredoc.php | 307 +++++ .../VeryLongPHP73Nowdoc.php | 1018 +++++++++++++++++ 6 files changed, 2222 insertions(+) create mode 100644 tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/StripNoise.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/VeryLongHeredoc.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/VeryLongNowdoc.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/VeryLongPHP73Heredoc.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/VeryLongPHP73Nowdoc.php diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index 1fb73c253..261fb7ced 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -244,6 +244,25 @@ class ClassMapGeneratorTest extends TestCase $fs->removeDirectory($tempDir); } + public function testCreateMapDoesNotHitRegexBacktraceLimit() + { + $expected = array( + 'Foo\\StripNoise' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/StripNoise.php', + 'Foo\\VeryLongHeredoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongHeredoc.php', + 'Foo\\ClassAfterLongHereDoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongHeredoc.php', + 'Foo\\VeryLongPHP73Heredoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongPHP73Heredoc.php', + 'Foo\\VeryLongPHP73Nowdoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongPHP73Nowdoc.php', + 'Foo\\ClassAfterLongNowDoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongPHP73Nowdoc.php', + 'Foo\\VeryLongNowdoc' => realpath(__DIR__) . '/Fixtures/pcrebacktracelimit/VeryLongNowdoc.php', + ); + + ini_set('pcre.backtrack_limit', '30000'); + $result = ClassMapGenerator::createMap(__DIR__ . '/Fixtures/pcrebacktracelimit'); + ini_restore('pcre.backtrack_limit'); + + $this->assertEqualsNormalized($expected, $result); + } + protected function assertEqualsNormalized($expected, $actual, $message = '') { foreach ($expected as $ns => $path) { diff --git a/tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/StripNoise.php b/tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/StripNoise.php new file mode 100644 index 000000000..8f93e8427 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/StripNoise.php @@ -0,0 +1,87 @@ +'; + } + + public function test_simple_string() + { + return 'class FailSimpleString {}'; + } +} diff --git a/tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/VeryLongHeredoc.php b/tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/VeryLongHeredoc.php new file mode 100644 index 000000000..11f87546d --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/pcrebacktracelimit/VeryLongHeredoc.php @@ -0,0 +1,464 @@ +