Skip to content

Commit 0ee570c

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 ef2ba3e commit 0ee570c

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
@@ -1006,10 +1006,10 @@ public function getConnectDuration(int $decimals = 6): string
10061006
* insert the table prefix (if it exists) in the proper position, and escape only
10071007
* the correct identifiers.
10081008
*
1009-
* @param array|string $item
1010-
* @param bool $prefixSingle Prefix a table name with no segments?
1011-
* @param bool $protectIdentifiers Protect table or column names?
1012-
* @param bool $fieldExists Supplied $item contains a column name?
1009+
* @param array|int|string $item
1010+
* @param bool $prefixSingle Prefix a table name with no segments?
1011+
* @param bool $protectIdentifiers Protect table or column names?
1012+
* @param bool $fieldExists Supplied $item contains a column name?
10131013
*
10141014
* @return array|string
10151015
* @phpstan-return ($item is array ? array : string)
@@ -1030,6 +1030,9 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro
10301030
return $escapedArray;
10311031
}
10321032

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

0 commit comments

Comments
 (0)