diff --git a/src/EntitySet.php b/src/EntitySet.php index dd1e64e99..ae264711a 100644 --- a/src/EntitySet.php +++ b/src/EntitySet.php @@ -266,6 +266,7 @@ public function get(Transaction $transaction, ?ContextInterface $context = null) } $this->assertValidOrderBy(); + $this->assertValidFilter(); return $transaction->getResponse()->setResourceCallback($this, function () use ($transaction, $context) { $context = $context ?: $this; @@ -1131,6 +1132,25 @@ protected function assertValidOrderBy(): void } } + /** + * Assert that the $filter expression is syntactically valid and references only known properties. + * This runs BEFORE the streaming response begins so that an invalid filter yields HTTP 400 + * rather than a malformed mid-stream error fragment. + * @return void + */ + protected function assertValidFilter(): void + { + $filter = $this->getFilter(); + + if (!$filter->hasValue()) { + return; + } + + $parser = $this->getFilterParser(); + $parser->pushEntitySet($this); + $parser->generateTree($filter->getExpression()); + } + /** * Assert that the attached type has searchable properties * @return void