Skip to content

Commit eeb1dc8

Browse files
committed
fix(dav): Allow array of array of scalars, and fix error message
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 2272860 commit eeb1dc8

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

apps/dav/lib/DAV/CustomPropertiesBackend.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,18 @@ private function formatPath(string $path): string {
571571
return $path;
572572
}
573573

574+
private static function checkIsArrayOfScalar(string $name, array $array): void {
575+
foreach ($array as $item) {
576+
if (is_array($item)) {
577+
self::checkIsArrayOfScalar($name, $item);
578+
} elseif ($item !== null && !is_scalar($item)) {
579+
throw new DavException(
580+
"Property \"$name\" has an invalid value of array containing " . gettype($item),
581+
);
582+
}
583+
}
584+
}
585+
574586
/**
575587
* @throws ParseException If parsing a \Sabre\DAV\Xml\Property\Complex value fails
576588
* @throws DavException If the property value is invalid
@@ -607,25 +619,20 @@ private function encodeValueForDatabase(string $path, string $name, mixed $value
607619
} else {
608620
if (is_array($value)) {
609621
// For array only allow scalar values
610-
foreach ($value as $item) {
611-
if (!is_scalar($item)) {
612-
throw new DavException(
613-
"Property \"$name\" has an invalid value of array containing " . gettype($value),
614-
);
615-
}
616-
}
622+
self::checkIsArrayOfScalar($name, $value);
617623
} elseif (!is_object($value)) {
618624
throw new DavException(
619625
"Property \"$name\" has an invalid value of type " . gettype($value),
620626
);
621-
}
622-
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
623-
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
624-
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
625-
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
626-
throw new DavException(
627-
"Property \"$name\" has an invalid value of class " . $value::class,
628-
);
627+
} else {
628+
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
629+
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
630+
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
631+
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
632+
throw new DavException(
633+
"Property \"$name\" has an invalid value of class " . $value::class,
634+
);
635+
}
629636
}
630637
$valueType = self::PROPERTY_TYPE_OBJECT;
631638
// serialize produces null character

0 commit comments

Comments
 (0)