Skip to content

Commit d7a9f8a

Browse files
committed
fix(Database): escape index identifiers in SQLite3 Table::dropIndexes()
1 parent 59e5eea commit d7a9f8a

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎docs/changelogs/v4.7.7.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Release Date: Unreleased
1616

1717
## Bugs Fixed
1818

19+
- **Database:** Fixed a bug where `SQLite3\Table::dropIndexes()` used single-quoted string literals instead of escaped identifiers in `DROP INDEX IF EXISTS`, causing syntax errors on index names containing quotes or special characters.
1920
- **HTTP:** Fixed a bug where `UploadedFile::move()` and `UploadedFile::store()` on Windows could store a file under a different name than `getName()` reported, or write its contents to an NTFS alternate data stream. Filenames ending in a period or space or containing a colon are now rejected, including explicitly supplied names.
2021
- **Security:** Fixed a bug where `Security::__construct()` threw a `TypeError` when the CSRF cookie was an array, causing an HTTP 500 response for affected requests.
2122
- **Worker Mode:** Fixed a bug where every request that ended with an uncaught exception, including a `404 Page Not Found` without a 404 override, called `exit()` in the exception handler. This ended the worker script, so FrankenPHP booted a new one, and the worker loop skipped its cleanup after the request. The exception handler now returns to the worker loop.

‎system/Database/SQLite3/Table.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ protected function dropIndexes()
496496
continue;
497497
}
498498

499-
$this->db->query("DROP INDEX IF EXISTS '{$name}'");
499+
$this->db->query('DROP INDEX IF EXISTS ' . $this->db->escapeIdentifier($name));
500500
}
501501
}
502502
}

‎tests/system/Database/Live/SQLite3/AlterTableTest.php‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,36 @@ public function testDropColumnKeepsForeignKeyTableNameWhenPrefixIsSet(): void
333333
$forge->dropTable('bandit_fk', true);
334334
}
335335

336+
public function testDropIndexesWithSpecialIndexName(): void
337+
{
338+
$this->createTable('special_table');
339+
$this->db->query("CREATE INDEX `special'index` ON `special_table`(`name`)");
340+
341+
$result = $this->table
342+
->fromTable('special_table')
343+
->dropColumn('email')
344+
->run();
345+
346+
$this->assertTrue($result);
347+
$this->forge->dropTable('special_table', true);
348+
$this->forge->dropTable('special_table_fk', true);
349+
}
350+
351+
public function testDropIndexesWithParenthesesInIndexName(): void
352+
{
353+
$this->createTable('special_table');
354+
$this->db->query('CREATE INDEX `special(index)` ON `special_table`(`email`)');
355+
356+
$result = $this->table
357+
->fromTable('special_table')
358+
->dropColumn('email')
359+
->run();
360+
361+
$this->assertTrue($result);
362+
$this->forge->dropTable('special_table', true);
363+
$this->forge->dropTable('special_table_fk', true);
364+
}
365+
336366
protected function createTable(string $tableName = 'foo'): void
337367
{
338368
// Create support table for foreign keys

0 commit comments

Comments
 (0)