Skip to content
Open
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
5 changes: 4 additions & 1 deletion system/Database/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ protected function _escapeString(string $str): string
$this->initialize();
}

return $this->connID->escapeString($str);
// SQLite3::escapeString() cannot handle NUL bytes: it silently
// truncated the string before PHP 8.6 and throws a ValueError since
// PHP 8.6. Escape the quotes ourselves so binary data is preserved.
return str_replace("'", "''", $str);
}

protected function _listTables(bool $prefixLimit = false, ?string $tableName = null): string
Expand Down
10 changes: 10 additions & 0 deletions tests/system/Database/Live/EscapeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,14 @@ public function testEscapeStringArray(): void

$this->assertSame('NULL', $escapedString[3]);
}

public function testNullBytesAreKept(): void
{
if ($this->db->DBDriver !== 'SQLite3') {
$this->markTestSkipped('Only the SQLite3 driver is affected.');
}

$this->assertSame("a\0b", $this->db->escapeString("a\0b"));
$this->assertSame("a''b\0c", $this->db->escapeString("a'b\0c"));
}
}
Loading