Skip to content

Commit a13c798

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 1a0b220 commit a13c798

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
@@ -566,6 +566,18 @@ private function formatPath(string $path): string {
566566
return $path;
567567
}
568568

569+
private static function checkIsArrayOfScalar(string $name, array $array): void {
570+
foreach ($array as $item) {
571+
if (is_array($item)) {
572+
self::checkIsArrayOfScalar($name, $array);
573+
} elseif ($item !== null && !is_scalar($item)) {
574+
throw new DavException(
575+
"Property \"$name\" has an invalid value of array containing " . gettype($item),
576+
);
577+
}
578+
}
579+
}
580+
569581
/**
570582
* @throws ParseException If parsing a \Sabre\DAV\Xml\Property\Complex value fails
571583
* @throws DavException If the property value is invalid
@@ -602,25 +614,20 @@ private function encodeValueForDatabase(string $path, string $name, mixed $value
602614
} else {
603615
if (is_array($value)) {
604616
// For array only allow scalar values
605-
foreach ($value as $item) {
606-
if (!is_scalar($item)) {
607-
throw new DavException(
608-
"Property \"$name\" has an invalid value of array containing " . gettype($value),
609-
);
610-
}
611-
}
617+
self::checkIsArrayOfScalar($name, $value);
612618
} elseif (!is_object($value)) {
613619
throw new DavException(
614620
"Property \"$name\" has an invalid value of type " . gettype($value),
615621
);
616-
}
617-
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
618-
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
619-
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
620-
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
621-
throw new DavException(
622-
"Property \"$name\" has an invalid value of class " . $value::class,
623-
);
622+
} else {
623+
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
624+
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
625+
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
626+
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
627+
throw new DavException(
628+
"Property \"$name\" has an invalid value of class " . $value::class,
629+
);
630+
}
624631
}
625632
$valueType = self::PROPERTY_TYPE_OBJECT;
626633
// serialize produces null character

0 commit comments

Comments
 (0)