Skip to content

Commit bf2a615

Browse files
authored
Add escapeLikeStringDirect for _listTables
1 parent 1e8e5c9 commit bf2a615

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

system/Database/MySQLi/Connection.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,49 @@ protected function _escapeString(string $str): string
389389

390390
//--------------------------------------------------------------------
391391

392+
/**
393+
* Escape Like String Direct
394+
* There are a few instances where MySQLi queries cannot take the
395+
* additional "ESCAPE x" parameter for specifying the escape character
396+
* in "LIKE" strings, and this handles those directly with a backslash.
397+
*
398+
* @param string|string[] $str Input string
399+
* @return string|string[]
400+
*/
401+
public function escapeLikeStringDirect($str)
402+
{
403+
if (is_array($str))
404+
{
405+
foreach ($str as $key => $val)
406+
{
407+
$str[$key] = $this->escapeLikeStringDirect($val);
408+
}
409+
410+
return $str;
411+
}
412+
413+
$str = $this->_escapeString($str);
414+
415+
// Escape LIKE condition wildcards
416+
return str_replace([
417+
$this->likeEscapeChar,
418+
'%',
419+
'_',
420+
], [
421+
'\\' . $this->likeEscapeChar,
422+
'\\' . '%',
423+
'\\' . '_',
424+
], $str
425+
);
426+
427+
return $str;
428+
}
429+
430+
//--------------------------------------------------------------------
431+
392432
/**
393433
* Generates the SQL for listing tables in a platform-dependent manner.
434+
* Uses escapeLikeStringDirect().
394435
*
395436
* @param boolean $prefixLimit
396437
*
@@ -402,7 +443,7 @@ protected function _listTables(bool $prefixLimit = false): string
402443

403444
if ($prefixLimit !== false && $this->DBPrefix !== '')
404445
{
405-
return $sql . " LIKE '" . $this->escapeLikeString($this->DBPrefix) . "%'";
446+
return $sql . " LIKE '" . $this->escapeLikeStringDirect($this->DBPrefix) . "%'";
406447
}
407448

408449
return $sql;

0 commit comments

Comments
 (0)