Skip to content

Commit e400db4

Browse files
come-ncbackportbot[bot]
authored andcommitted
fix(dav): Allow array of array of scalars, and fix error message
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 6572039 commit e400db4

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
@@ -480,6 +480,18 @@ private function formatPath(string $path): string {
480480
return $path;
481481
}
482482

483+
private static function checkIsArrayOfScalar(string $name, array $array): void {
484+
foreach ($array as $item) {
485+
if (is_array($item)) {
486+
self::checkIsArrayOfScalar($name, $item);
487+
} elseif ($item !== null && !is_scalar($item)) {
488+
throw new DavException(
489+
"Property \"$name\" has an invalid value of array containing " . gettype($item),
490+
);
491+
}
492+
}
493+
}
494+
483495
/**
484496
* @throws ParseException If parsing a \Sabre\DAV\Xml\Property\Complex value fails
485497
* @throws DavException If the property value is invalid
@@ -516,25 +528,20 @@ private function encodeValueForDatabase(string $path, string $name, mixed $value
516528
} else {
517529
if (is_array($value)) {
518530
// For array only allow scalar values
519-
foreach ($value as $item) {
520-
if (!is_scalar($item)) {
521-
throw new DavException(
522-
"Property \"$name\" has an invalid value of array containing " . gettype($value),
523-
);
524-
}
525-
}
531+
self::checkIsArrayOfScalar($name, $value);
526532
} elseif (!is_object($value)) {
527533
throw new DavException(
528534
"Property \"$name\" has an invalid value of type " . gettype($value),
529535
);
530-
}
531-
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
532-
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
533-
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
534-
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
535-
throw new DavException(
536-
"Property \"$name\" has an invalid value of class " . $value::class,
537-
);
536+
} else {
537+
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
538+
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
539+
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
540+
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
541+
throw new DavException(
542+
"Property \"$name\" has an invalid value of class " . $value::class,
543+
);
544+
}
538545
}
539546
$valueType = self::PROPERTY_TYPE_OBJECT;
540547
// serialize produces null character

0 commit comments

Comments
 (0)