From 92cef58f2a6cd169dcf389826fdf0b3eb9bd1ba8 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Tue, 4 Jul 2023 10:10:53 +0000 Subject: [PATCH] unify checking methods, fixes #2815 Closes #2815 Merge request studip/studip!1897 --- .../JsonApiIntegration/QueryChecker.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/classes/JsonApi/JsonApiIntegration/QueryChecker.php b/lib/classes/JsonApi/JsonApiIntegration/QueryChecker.php index ff2a03d26de..d1b209a4a3f 100644 --- a/lib/classes/JsonApi/JsonApiIntegration/QueryChecker.php +++ b/lib/classes/JsonApi/JsonApiIntegration/QueryChecker.php @@ -104,15 +104,15 @@ class QueryChecker protected function checkSorting(ErrorCollection $errors, QueryParserInterface $queryParser): void { - if (null !== $queryParser->getSorts() && null !== $this->sortParameters) { - foreach ($queryParser->getSorts() as $sortParameter) { - if (!array_key_exists($sortParameter->getField(), $this->sortParameters)) { - $errors->addQueryParameterError( - QueryParser::PARAM_SORT, - sprintf('Sort parameter %s is not allowed.', $sortParameter->getField()) - ); - } - } + $withinAllowed = $this->keysWithinAllowed( + iterator_to_array($queryParser->getSorts()), + $this->sortParameters + ); + if (!$withinAllowed) { + $errors->addQueryParameterError( + QueryParser::PARAM_SORT, + 'Sort parameter should contain only allowed values.' + ); } } -- GitLab