From fe4ac0e10d98221c0a1ce905e6bf640d78fd68af Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 1 Dec 2026 15:45:23 +1300 Subject: [PATCH] fix(query): refuse keyed values in a having and()/or() group Validating group conditions directly skipped Filter's list-shape check, so an object of conditions passed. Co-Authored-By: Claude Opus 5.5 --- src/Database/Validator/Query/Having.php | 6 ++++++ tests/unit/Validator/QueryShapeHavingTest.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/Database/Validator/Query/Having.php b/src/Database/Validator/Query/Having.php index e490561fb..2573b303e 100644 --- a/src/Database/Validator/Query/Having.php +++ b/src/Database/Validator/Query/Having.php @@ -226,6 +226,12 @@ private function isValidLogicalCondition(Query $condition, Filter $filter): bool $method = $condition->getMethod(); $children = $condition->getValues(); + if (! \array_is_list($children)) { + $this->message = \ucfirst($method->value).' query values must be a list'; + + return false; + } + foreach ($children as $child) { if (! $child instanceof Query) { $this->message = \ucfirst($method->value).' queries can only contain filter queries'; diff --git a/tests/unit/Validator/QueryShapeHavingTest.php b/tests/unit/Validator/QueryShapeHavingTest.php index b64751ecf..fa522e046 100644 --- a/tests/unit/Validator/QueryShapeHavingTest.php +++ b/tests/unit/Validator/QueryShapeHavingTest.php @@ -118,6 +118,10 @@ public static function invalidHavingProvider(): array [Query::sum('price', 'total'), Query::groupBy(['name']), Query::having([new Query(Method::And, '', ['total', Query::greaterThan('total', 10)])])], 'And queries can only contain filter queries', ], + 'logical group with keyed conditions' => [ + [Query::sum('price', 'total'), Query::groupBy(['name']), Query::having([new Query(Method::Or, '', ['high' => Query::greaterThan('total', 10), 'low' => Query::lessThan('total', 1)])])], + 'Or query values must be a list', + ], 'alias inside a logical group with an operator an aggregate cannot take' => [ [Query::sum('price', 'total'), Query::groupBy(['name']), Query::having([Query::and([Query::equal('name', ['x']), Query::startsWith('total', '1')])])], 'Aggregate alias "total" cannot be compared with startsWith',