Skip to content

Commit 3b1e984

Browse files
authored
Merge pull request #5372 from kenjis/fix-array_helper
fix: `dot_array_search()` unexpected array structure causes Type Error
2 parents be1908f + b367e05 commit 3b1e984

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

system/Helpers/array_helper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ function _array_search_dot(array $indexes, array $array)
5353
$answer = [];
5454

5555
foreach ($array as $value) {
56+
if (! is_array($value)) {
57+
return null;
58+
}
59+
5660
$answer[] = _array_search_dot($indexes, $value);
5761
}
5862

tests/system/Helpers/ArrayHelperTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ public function testArrayDotTooManyLevels()
4646
$this->assertSame(23, dot_array_search('foo.bar.baz', $data));
4747
}
4848

49+
/**
50+
* @see https://github.com/codeigniter4/CodeIgniter4/issues/5369
51+
*/
52+
public function testArrayDotValueIsListArray()
53+
{
54+
$data = [
55+
'arr' => [1, 2, 3],
56+
];
57+
58+
$this->assertNull(dot_array_search('arr.*.index', $data));
59+
}
60+
4961
public function testArrayDotEscape()
5062
{
5163
$data = [

0 commit comments

Comments
 (0)