From e33fcfddc1a27917df7f6a2d2034e90ce3b121b0 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 19 Mar 2025 19:07:28 +0100 Subject: [PATCH] fix(dav): throw invalid argument when property type does not match * Resolves https://github.com/nextcloud/server/issues/49972 Currently a TypeError is thrown when casting fails, this lead to a HTTP 500 error. Instead throw a proper InvalidArgumentError so the user receives a HTTP 400. Signed-off-by: Ferdinand Thiessen --- apps/dav/lib/Files/FileSearchBackend.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php index 1b785962112..ace367e4490 100644 --- a/apps/dav/lib/Files/FileSearchBackend.php +++ b/apps/dav/lib/Files/FileSearchBackend.php @@ -422,10 +422,16 @@ class FileSearchBackend implements ISearchBackend { $field = $this->mapPropertyNameToColumn($property); } + try { + $castedValue = $this->castValue($property, $value ?? ''); + } catch (\Error $e) { + throw new \InvalidArgumentException('Invalid property value for ' . $property->name, previous: $e); + } + return new SearchComparison( $trimmedType, $field, - $this->castValue($property, $value ?? ''), + $castedValue, $extra ?? '' );