Skip to content

Commit 0772251

Browse files
committed
refactor: fix TypeError in BaseConnection
1) CodeIgniter\Models\InsertModelTest::testInsertPermitInsertNoData TypeError: strcspn(): Argument #1 ($string) must be of type string, int given /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseConnection.php:1042 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Database/BaseConnection.php:1029 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Model.php:308 /home/runner/work/CodeIgniter4/CodeIgniter4/system/BaseModel.php:782 /home/runner/work/CodeIgniter4/CodeIgniter4/system/Model.php:707 /home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/Models/InsertModelTest.php:255
1 parent 1497faf commit 0772251

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

system/Database/BaseConnection.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,10 +1008,10 @@ public function getConnectDuration(int $decimals = 6): string
10081008
* insert the table prefix (if it exists) in the proper position, and escape only
10091009
* the correct identifiers.
10101010
*
1011-
* @param array|string $item
1012-
* @param bool $prefixSingle Prefix a table name with no segments?
1013-
* @param bool $protectIdentifiers Protect table or column names?
1014-
* @param bool $fieldExists Supplied $item contains a column name?
1011+
* @param array|int|string $item
1012+
* @param bool $prefixSingle Prefix a table name with no segments?
1013+
* @param bool $protectIdentifiers Protect table or column names?
1014+
* @param bool $fieldExists Supplied $item contains a column name?
10151015
*
10161016
* @return array|string
10171017
* @phpstan-return ($item is array ? array : string)
@@ -1032,6 +1032,9 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro
10321032
return $escapedArray;
10331033
}
10341034

1035+
// If you pass `['column1', 'column2']`, `$item` will be int because the array keys are int.
1036+
$item = (string) $item;
1037+
10351038
// This is basically a bug fix for queries that use MAX, MIN, etc.
10361039
// If a parenthesis is found we know that we do not need to
10371040
// escape the data or add a prefix. There's probably a more graceful

0 commit comments

Comments
 (0)