fix(metadata): properly handle casting non-numeric values in search operations with custom metadata

If a metadata property is declared with a number type but the value provided are not numeric, it
logs "A non-numeric value encountered at nextcloud/apps/dav/lib/Files/FileSearchBackend.php#486" instead of throwing a proper error.

Now with a proper error we have the proper exception being thrown: InvalidArgumentException Invalid
property value for {http://nextcloud.org/ns}metadata-photos-original_date_time

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2025-09-19 11:55:25 +02:00
parent 0c6e396394
commit 974cfef214
No known key found for this signature in database

View file

@ -482,7 +482,10 @@ class FileSearchBackend implements ISearchBackend {
case SearchPropertyDefinition::DATATYPE_DECIMAL:
case SearchPropertyDefinition::DATATYPE_INTEGER:
case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER:
return 0 + $value;
if (is_numeric($value)) {
return 0 + $value;
}
throw new \Error('Value for numeric datatype is not numeric');
case SearchPropertyDefinition::DATATYPE_DATETIME:
if (is_numeric($value)) {
return max(0, 0 + $value);