Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/MigrationCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ private function executeQueryFile(string $filename): void
$start = 0;
$end = 0;
} else {
$line = trim((string)preg_replace('/--.*/', '', $line));
if ($line === '') {
continue;
}
$start = $start > 0 ? $start : $index;
$end = $index;
$current_request .= $current_request !== '' ? PHP_EOL : '';
Expand Down
37 changes: 37 additions & 0 deletions test/MigrationCoreSecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,41 @@ public function testUntamperedMigrationDoesNotRaiseException(): void
$this->runSilent($core);
$this->addToAssertionCount(1);
}

// -------------------------------------------------------------------------
// Nettoyage des commentaires SQL
// -------------------------------------------------------------------------

public function testSqlLineCommentIsStripped(): void
{
$sql = "CREATE TABLE comment_test (id INTEGER PRIMARY KEY) -- cette table est un test";
$this->createSqlFile($sql);
$core = $this->makeCoreWithDb();
$this->runSilent($core);
$this->addToAssertionCount(1);
}

public function testFullyCommentedOutQueryIsIgnored(): void
{
$sql = "CREATE TABLE comment_only_test (id INTEGER PRIMARY KEY)\n---\n-- DROP TABLE comment_only_test";
$this->createSqlFile($sql);
$core = $this->makeCoreWithDb();
$this->runSilent($core);
$this->addToAssertionCount(1);
}

public function testMixedCommentAndRealSqlExecutesCorrectly(): void
{
$sql = implode("\n", [
'-- création de la table',
'CREATE TABLE mixed_comment_test (id INTEGER PRIMARY KEY)',
'---',
'-- requête mise en commentaire',
'-- DROP TABLE mixed_comment_test',
]);
$this->createSqlFile($sql);
$core = $this->makeCoreWithDb();
$this->runSilent($core);
$this->addToAssertionCount(1);
}
}