Skip to content

Commit f015dbe

Browse files
committed
fix: $db->escape() does not accept Stringable
1 parent 393181b commit f015dbe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

system/Database/BaseConnection.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use CodeIgniter\Database\Exceptions\DatabaseException;
1818
use CodeIgniter\Events\Events;
1919
use stdClass;
20+
use Stringable;
2021
use Throwable;
2122

2223
/**
@@ -1309,12 +1310,15 @@ public function escape($str)
13091310
return array_map($this->escape(...), $str);
13101311
}
13111312

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

1318+
$str = (string) $str;
1319+
}
1320+
1321+
if (is_string($str)) {
13181322
return "'" . $this->escapeString($str) . "'";
13191323
}
13201324

0 commit comments

Comments
 (0)