diff --git a/src/Database/Validator/Query/Filter.php b/src/Database/Validator/Query/Filter.php index ca124ec28..50427c015 100644 --- a/src/Database/Validator/Query/Filter.php +++ b/src/Database/Validator/Query/Filter.php @@ -316,7 +316,8 @@ protected function isEmpty(array $values): bool return true; } - if (is_array($values[0]) && count($values[0]) === 0) { + $firstKey = \array_key_first($values); + if (\is_array($values[$firstKey]) && \count($values[$firstKey]) === 0) { return true; } diff --git a/tests/unit/Validator/Query/FilterTest.php b/tests/unit/Validator/Query/FilterTest.php index 21ba8f404..4bdff1270 100644 --- a/tests/unit/Validator/Query/FilterTest.php +++ b/tests/unit/Validator/Query/FilterTest.php @@ -122,6 +122,16 @@ public function testEmptyValues(): void $this->assertEquals('Equal queries require at least one value.', $this->validator->getDescription()); } + public function testIsEmptyHandlesNonZeroIndexedValues(): void + { + // Sparse / associative arrays must not trigger "Undefined array key 0". + $sparse = new Query(Query::TYPE_EQUAL, 'string', [1 => 'super']); + $this->assertTrue($this->validator->isValid($sparse)); + + $assoc = new Query(Query::TYPE_CONTAINS, 'string_array', ['foo' => 'super']); + $this->assertTrue($this->validator->isValid($assoc)); + } + public function testMaxValuesCount(): void { $max = $this->validator->getMaxValuesCount();