From 59b7377670f2e902eca2f95ff7d09d379987f10d Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Thu, 19 Nov 2026 20:53:34 +0800 Subject: [PATCH] fix: return false from `ArrayHelper::dotHas()` for a wildcard over an empty array --- system/Helpers/Array/ArrayHelper.php | 8 +++++++- tests/system/Helpers/Array/ArrayHelperDotHasTest.php | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/system/Helpers/Array/ArrayHelper.php b/system/Helpers/Array/ArrayHelper.php index 2f219cfd6b38..7325922ad7f2 100644 --- a/system/Helpers/Array/ArrayHelper.php +++ b/system/Helpers/Array/ArrayHelper.php @@ -171,7 +171,13 @@ private static function hasByDotPath(array|object $array, array $indexes): bool $currentIndex = array_shift($indexes); if ($currentIndex === '*') { - foreach (self::entries($array) as $item) { + $entries = self::entries($array); + + if ($entries === []) { + return false; + } + + foreach ($entries as $item) { if (! self::isNavigable($item) || ! self::hasByDotPath($item, $indexes)) { return false; } diff --git a/tests/system/Helpers/Array/ArrayHelperDotHasTest.php b/tests/system/Helpers/Array/ArrayHelperDotHasTest.php index de859f14dd98..b9d962aade0f 100644 --- a/tests/system/Helpers/Array/ArrayHelperDotHasTest.php +++ b/tests/system/Helpers/Array/ArrayHelperDotHasTest.php @@ -73,6 +73,8 @@ public function testDotHasWithWildCard(): void $this->assertTrue(ArrayHelper::dotHas('contacts.*.1.age', $this->array)); $this->assertTrue(ArrayHelper::dotHas('contacts.*.0.name', $this->array)); $this->assertFalse(ArrayHelper::dotHas('contacts.*.1.name', $this->array)); + $this->assertFalse(ArrayHelper::dotHas('*.name', [])); + $this->assertFalse(ArrayHelper::dotHas('contacts.friends.*.name', ['contacts' => ['friends' => []]])); } public function testDotHasWithZeroKeyAndNonArrayValues(): void