Skip to content

Commit

Permalink
refactor: fix TypeError in BaseConnection
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kenjis committed Nov 29, 2023
1 parent 1497faf commit 0772251
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1008,10 +1008,10 @@ public function getConnectDuration(int $decimals = 6): string
* insert the table prefix (if it exists) in the proper position, and escape only
* the correct identifiers.
*
* @param array|string $item
* @param bool $prefixSingle Prefix a table name with no segments?
* @param bool $protectIdentifiers Protect table or column names?
* @param bool $fieldExists Supplied $item contains a column name?
* @param array|int|string $item
* @param bool $prefixSingle Prefix a table name with no segments?
* @param bool $protectIdentifiers Protect table or column names?
* @param bool $fieldExists Supplied $item contains a column name?
*
* @return array|string
* @phpstan-return ($item is array ? array : string)
Expand All @@ -1032,6 +1032,9 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro
return $escapedArray;
}

// If you pass `['column1', 'column2']`, `$item` will be int because the array keys are int.
$item = (string) $item;

// This is basically a bug fix for queries that use MAX, MIN, etc.
// If a parenthesis is found we know that we do not need to
// escape the data or add a prefix. There's probably a more graceful
Expand Down

0 comments on commit 0772251

Please sign in to comment.