Skip to content

Commit

Permalink
fix: _escapeString() should accept Stringable
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Apr 9, 2024
1 parent 0d1c6b9 commit db17a77
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
9 changes: 5 additions & 4 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Events\Events;
use stdClass;
use Stringable;
use Throwable;

/**
Expand Down Expand Up @@ -1328,8 +1329,8 @@ public function escape($str)
/**
* Escape String
*
* @param list<string>|string $str Input string
* @param bool $like Whether or not the string will be used in a LIKE condition
* @param list<string|Stringable>|string|Stringable $str Input string
* @param bool $like Whether the string will be used in a LIKE condition
*
* @return list<string>|string
*/
Expand Down Expand Up @@ -1371,7 +1372,7 @@ public function escapeString($str, bool $like = false)
* Calls the individual driver for platform
* specific escaping for LIKE conditions
*
* @param list<string>|string $str
* @param list<string|Stringable>|string|Stringable $str
*
* @return list<string>|string
*/
Expand All @@ -1385,7 +1386,7 @@ public function escapeLikeString($str)
*
* Will likely be overridden in child classes.
*/
protected function _escapeString(string $str): string
protected function _escapeString(string|Stringable $str): string
{
return str_replace("'", "''", remove_invisible_characters($str, false));
}
Expand Down
3 changes: 2 additions & 1 deletion system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use mysqli_result;
use mysqli_sql_exception;
use stdClass;
use Stringable;
use Throwable;

/**
Expand Down Expand Up @@ -342,7 +343,7 @@ public function affectedRows(): int
/**
* Platform-dependant string escape
*/
protected function _escapeString(string $str): string
protected function _escapeString(string|Stringable $str): string
{
if (! $this->connID) {
$this->initialize();
Expand Down
3 changes: 2 additions & 1 deletion system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PgSql\Connection as PgSqlConnection;
use PgSql\Result as PgSqlResult;
use stdClass;
use Stringable;

/**
* Connection for Postgre
Expand Down Expand Up @@ -253,7 +254,7 @@ public function escape($str)
/**
* Platform-dependant string escape
*/
protected function _escapeString(string $str): string
protected function _escapeString(string|Stringable $str): string
{
if (! $this->connID) {
$this->initialize();
Expand Down
3 changes: 2 additions & 1 deletion system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CodeIgniter\Database\BaseConnection;
use CodeIgniter\Database\Exceptions\DatabaseException;
use stdClass;
use Stringable;

/**
* Connection for SQLSRV
Expand Down Expand Up @@ -182,7 +183,7 @@ protected function _close()
/**
* Platform-dependant string escape
*/
protected function _escapeString(string $str): string
protected function _escapeString(string|Stringable $str): string
{
return str_replace("'", "''", remove_invisible_characters($str, false));
}
Expand Down
3 changes: 2 additions & 1 deletion system/Database/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use SQLite3;
use SQLite3Result;
use stdClass;
use Stringable;

/**
* Connection for SQLite3
Expand Down Expand Up @@ -171,7 +172,7 @@ public function affectedRows(): int
/**
* Platform-dependant string escape
*/
protected function _escapeString(string $str): string
protected function _escapeString(string|Stringable $str): string
{
if (! $this->connID instanceof SQLite3) {
$this->initialize();
Expand Down

0 comments on commit db17a77

Please sign in to comment.