Skip to content

Commit 36ce316

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 a8df5c5 commit 36ce316

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
@@ -531,6 +531,18 @@ private function formatPath(string $path): string {
531531
return $path;
532532
}
533533

534+
private static function checkIsArrayOfScalar(string $name, array $array): void {
535+
foreach ($array as $item) {
536+
if (is_array($item)) {
537+
self::checkIsArrayOfScalar($name, $item);
538+
} elseif ($item !== null && !is_scalar($item)) {
539+
throw new DavException(
540+
"Property \"$name\" has an invalid value of array containing " . gettype($item),
541+
);
542+
}
543+
}
544+
}
545+
534546
/**
535547
* @throws ParseException If parsing a \Sabre\DAV\Xml\Property\Complex value fails
536548
* @throws DavException If the property value is invalid
@@ -567,25 +579,20 @@ private function encodeValueForDatabase(string $path, string $name, mixed $value
567579
} else {
568580
if (is_array($value)) {
569581
// For array only allow scalar values
570-
foreach ($value as $item) {
571-
if (!is_scalar($item)) {
572-
throw new DavException(
573-
"Property \"$name\" has an invalid value of array containing " . gettype($value),
574-
);
575-
}
576-
}
582+
self::checkIsArrayOfScalar($name, $value);
577583
} elseif (!is_object($value)) {
578584
throw new DavException(
579585
"Property \"$name\" has an invalid value of type " . gettype($value),
580586
);
581-
}
582-
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
583-
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
584-
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
585-
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
586-
throw new DavException(
587-
"Property \"$name\" has an invalid value of class " . $value::class,
588-
);
587+
} else {
588+
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
589+
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
590+
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
591+
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
592+
throw new DavException(
593+
"Property \"$name\" has an invalid value of class " . $value::class,
594+
);
595+
}
589596
}
590597
$valueType = self::PROPERTY_TYPE_OBJECT;
591598
// serialize produces null character

0 commit comments

Comments
 (0)