Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions apps/dav/lib/Files/FileSearchBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,16 +505,36 @@ private function castValue(SearchPropertyDefinition $property, $value) {
case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER:
return 0 + $value;
case SearchPropertyDefinition::DATATYPE_DATETIME:
if (is_numeric($value)) {
return max(0, 0 + $value);
}
$date = \DateTime::createFromFormat(\DateTimeInterface::ATOM, (string)$value);
return ($date instanceof \DateTime && $date->getTimestamp() !== false) ? $date->getTimestamp() : 0;
return $this->castDateTimeValue($value);
default:
return $value;
}
}

private function castDateTimeValue($value) {
if (is_numeric($value)) {
return max(0, 0 + $value);
}

$date = \DateTime::createFromFormat(\DateTimeInterface::ATOM, (string)$value);
if (!$date instanceof \DateTime) {
return 0;
}

try {
return $date->getTimestamp();
} catch (\Error $e) {
if (!$e instanceof \ValueError && !is_a($e, 'DateRangeError')) {
throw $e;
}

// On 32-bit PHP, getTimestamp() fails for dates outside the
// representable integer range. Clamp broad search bounds instead of
// failing the whole WebDAV SEARCH request.
return (int) $date->format("Y") >= 2038 ? PHP_INT_MAX : 0;
}
}

/**
* Get a specific property from the were clause
*/
Expand Down