Skip to content

Commit b2ba91b

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 cfe6b46 commit b2ba91b

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
@@ -430,6 +430,18 @@ private function formatPath(string $path): string {
430430
return $path;
431431
}
432432

433+
private static function checkIsArrayOfScalar(string $name, array $array): void {
434+
foreach ($array as $item) {
435+
if (is_array($item)) {
436+
self::checkIsArrayOfScalar($name, $item);
437+
} elseif ($item !== null && !is_scalar($item)) {
438+
throw new DavException(
439+
"Property \"$name\" has an invalid value of array containing " . gettype($item),
440+
);
441+
}
442+
}
443+
}
444+
433445
/**
434446
* @param mixed $value
435447
* @return array
@@ -443,25 +455,20 @@ private function encodeValueForDatabase($value): array {
443455
} else {
444456
if (is_array($value)) {
445457
// For array only allow scalar values
446-
foreach ($value as $item) {
447-
if (!is_scalar($item)) {
448-
throw new DavException(
449-
"Property \"$name\" has an invalid value of array containing " . gettype($value),
450-
);
451-
}
452-
}
458+
self::checkIsArrayOfScalar($name, $value);
453459
} elseif (!is_object($value)) {
454460
throw new DavException(
455461
"Property \"$name\" has an invalid value of type " . gettype($value),
456462
);
457-
}
458-
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
459-
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
460-
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
461-
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
462-
throw new DavException(
463-
"Property \"$name\" has an invalid value of class " . $value::class,
464-
);
463+
} else {
464+
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
465+
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
466+
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
467+
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
468+
throw new DavException(
469+
"Property \"$name\" has an invalid value of class " . $value::class,
470+
);
471+
}
465472
}
466473
$valueType = self::PROPERTY_TYPE_OBJECT;
467474
$value = serialize($value);

0 commit comments

Comments
 (0)