Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Database/Validator/Query/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/Validator/Query/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading