diff --git a/typo3/sysext/core/Classes/Database/Schema/SqlReader.php b/typo3/sysext/core/Classes/Database/Schema/SqlReader.php index 120f962feb8843bdf158cb9ce31ffc818b3d5122..0a2ffc1f3b3f447f13550d19633edbdcfc196010 100644 --- a/typo3/sysext/core/Classes/Database/Schema/SqlReader.php +++ b/typo3/sysext/core/Classes/Database/Schema/SqlReader.php @@ -89,11 +89,21 @@ class SqlReader { $statementArray = []; $statementArrayPointer = 0; + $isInMultilineComment = false; foreach (explode(LF, $dumpContent) as $lineContent) { $lineContent = trim($lineContent); // Skip empty lines and comments - if ($lineContent === '' || $lineContent[0] === '#' || strpos($lineContent, '--') === 0) { + if ($lineContent === '' || $lineContent[0] === '#' || strpos($lineContent, '--') === 0 || + strpos($lineContent, '/*') === 0 || substr($lineContent, -2) === '*/' || $isInMultilineComment + ) { + // skip c style multiline comments + if (strpos($lineContent, '/*') === 0 && substr($lineContent, -2) !== '*/') { + $isInMultilineComment = true; + } + if (substr($lineContent, -2) === '*/') { + $isInMultilineComment = false; + } continue; } diff --git a/typo3/sysext/core/Tests/Unit/Database/Schema/SqlReaderTest.php b/typo3/sysext/core/Tests/Unit/Database/Schema/SqlReaderTest.php index 9c64f6f08f02f756feb614f9b6c492ee8a7bacc8..c40d7674baa0af662a87a5b2099d375211a94711 100644 --- a/typo3/sysext/core/Tests/Unit/Database/Schema/SqlReaderTest.php +++ b/typo3/sysext/core/Tests/Unit/Database/Schema/SqlReaderTest.php @@ -111,4 +111,42 @@ class SqlReaderTest extends UnitTestCase self::assertCount(1, $result); self::assertStringStartsWith('CREATE TABLE', array_pop($result)); } + + /** + * @param string $comment + * @dataProvider commentProvider + * @test + */ + public function getCreateTableStatementArrayResultWithComment(string $comment) + { + $subject = new SqlReader($this->prophesize(EventDispatcherInterface::class)->reveal(), $this->prophesize(PackageManager::class)->reveal()); + $result = $subject->getCreateTableStatementArray( + $comment . LF . 'CREATE TABLE aTestTable(' . LF . ' aTestField INT(11)' . LF . ');' . + LF . + 'INSERT INTO aTestTable(`aTestField`) VALUES(1);' + ); + self::assertCount(1, $result); + self::assertStringStartsWith('CREATE TABLE', array_pop($result)); + } + + public function commentProvider(): array + { + return [ + 'Single line comment starting with "#"' => [ + '# Comment' + ], + 'Single line comment starting with "--"' => [ + '-- Comment' + ], + 'Single line c-style comment' => [ + '/* Same line c-style comment */' + ], + 'Multiline comment variant 1' => [ + '/*' . LF . 'Some comment text' . LF . 'more text' . LF . '*/' + ], + 'Multiline comment variant 2' => [ + '/* More' . LF . ' comments */' + ] + ]; + } }