From 33837e7d6fb57d657a197a4f49549d919b1ebc62 Mon Sep 17 00:00:00 2001 From: Benjamin Gaussorgues Date: Wed, 15 Nov 2023 10:13:57 +0100 Subject: [PATCH] Fix invalid users/groups handling in advanced search Signed-off-by: Benjamin Gaussorgues --- core/Controller/UnifiedSearchController.php | 3 ++- lib/private/Search/Filter/GroupFilter.php | 5 +++-- lib/private/Search/Filter/UserFilter.php | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/Controller/UnifiedSearchController.php b/core/Controller/UnifiedSearchController.php index 87aa84e1d91b6..5ae99c6a07644 100644 --- a/core/Controller/UnifiedSearchController.php +++ b/core/Controller/UnifiedSearchController.php @@ -28,6 +28,7 @@ */ namespace OC\Core\Controller; +use InvalidArgumentException; use OC\Search\SearchComposer; use OC\Search\SearchQuery; use OCA\Core\ResponseDefinitions; @@ -111,7 +112,7 @@ public function search( try { $filters = $this->composer->buildFilterList($providerId, $this->request->getParams()); - } catch (UnsupportedFilter $e) { + } catch (UnsupportedFilter|InvalidArgumentException $e) { return new DataResponse($e->getMessage(), Http::STATUS_BAD_REQUEST); } return new DataResponse( diff --git a/lib/private/Search/Filter/GroupFilter.php b/lib/private/Search/Filter/GroupFilter.php index 6b42492824c4b..f0b34a360cace 100644 --- a/lib/private/Search/Filter/GroupFilter.php +++ b/lib/private/Search/Filter/GroupFilter.php @@ -38,10 +38,11 @@ public function __construct( string $value, IGroupManager $groupManager, ) { - $this->group = $groupManager->get($value); - if ($this->group === null) { + $group = $groupManager->get($value); + if ($group === null) { throw new InvalidArgumentException('Group '.$value.' not found'); } + $this->group = $group; } public function get(): IGroup { diff --git a/lib/private/Search/Filter/UserFilter.php b/lib/private/Search/Filter/UserFilter.php index 1624b60d1a307..963d5e123ac84 100644 --- a/lib/private/Search/Filter/UserFilter.php +++ b/lib/private/Search/Filter/UserFilter.php @@ -38,10 +38,11 @@ public function __construct( string $value, IUserManager $userManager, ) { - $this->user = $userManager->get($value); - if ($this->user === null) { + $user = $userManager->get($value); + if ($user === null) { throw new InvalidArgumentException('User '.$value.' not found'); } + $this->user = $user; } public function get(): IUser {