Skip to content

Commit

Permalink
fix: $db->escape() does not accept Stringable
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Apr 10, 2024
1 parent 393181b commit f015dbe
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 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 @@ -1309,12 +1310,15 @@ public function escape($str)
return array_map($this->escape(...), $str);
}

/** @psalm-suppress NoValue I don't know why ERROR. */
if (is_string($str) || (is_object($str) && method_exists($str, '__toString'))) {
if ($str instanceof Stringable) {
if ($str instanceof RawSql) {
return $str->__toString();
}

$str = (string) $str;
}

if (is_string($str)) {
return "'" . $this->escapeString($str) . "'";
}

Expand Down

0 comments on commit f015dbe

Please sign in to comment.