Skip to content
Merged
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
14 changes: 5 additions & 9 deletions Sources/Db/APIs/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ public function query(string $db_string, array $db_values = [], ?object $connect
{
// Comments that are allowed in a query are preg_removed.
$allowed_comments_from = [
'~\'\X*?\'~s',
'~\s+~s',
'~/\*!40001 SQL_NO_CACHE \*/~',
'~/\*!40000 USE INDEX \([A-Za-z\_]+?\) \*/~',
'~/\*!40100 ON DUPLICATE KEY UPDATE id_msg = \d+ \*/~',
];
$allowed_comments_to = [
' %s ',
' ',
'',
'',
Expand Down Expand Up @@ -169,18 +171,12 @@ public function query(string $db_string, array $db_values = [], ?object $connect

// First, we clean strings out of the query, reduce whitespace, lowercase, and trim - so we can check it over.
if (!$this->disableQueryCheck) {
$clean = preg_split('/(?:\\\\{2})*\K(?<![\'\\\\])\'(?![\'])/', $db_string);

for ($i = 0; $i < \count($clean); $i++) {
if ($i % 2 === 1) {
$clean[$i] = ' %s ';
}
}

// Clear out escaped backslashes & single quotes first, to make it simpler to ID & remove string literals
$clean = str_replace(array('\\\\', '\\\'', '\'\''), array('', '', ''), $db_string);
$clean = trim(strtolower(preg_replace(
$allowed_comments_from,
$allowed_comments_to,
implode('', $clean),
$clean,
)));

if (
Expand Down