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 <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2025-03-19 19:07:28 +01:00 committed by Andy Scherzinger
parent 5862d5aea1
commit e33fcfddc1

View file

@ -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 ?? ''
);