Skip to content

Commit e164506

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 <[email protected]>
1 parent 472e430 commit e164506

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
@@ -415,6 +415,18 @@ private function formatPath(string $path): string {
415415
return $path;
416416
}
417417

418+
private static function checkIsArrayOfScalar(string $name, array $array): void {
419+
foreach ($array as $item) {
420+
if (is_array($item)) {
421+
self::checkIsArrayOfScalar($name, $item);
422+
} elseif ($item !== null && !is_scalar($item)) {
423+
throw new DavException(
424+
"Property \"$name\" has an invalid value of array containing " . gettype($item),
425+
);
426+
}
427+
}
428+
}
429+
418430
/**
419431
* @param mixed $value
420432
* @return array
@@ -428,25 +440,20 @@ private function encodeValueForDatabase($value): array {
428440
} else {
429441
if (is_array($value)) {
430442
// For array only allow scalar values
431-
foreach ($value as $item) {
432-
if (!is_scalar($item)) {
433-
throw new DavException(
434-
"Property \"$name\" has an invalid value of array containing " . gettype($value),
435-
);
436-
}
437-
}
443+
self::checkIsArrayOfScalar($name, $value);
438444
} elseif (!is_object($value)) {
439445
throw new DavException(
440446
"Property \"$name\" has an invalid value of type " . gettype($value),
441447
);
442-
}
443-
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
444-
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
445-
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
446-
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
447-
throw new DavException(
448-
"Property \"$name\" has an invalid value of class " . $value::class,
449-
);
448+
} else {
449+
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
450+
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
451+
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
452+
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
453+
throw new DavException(
454+
"Property \"$name\" has an invalid value of class " . $value::class,
455+
);
456+
}
450457
}
451458
$valueType = self::PROPERTY_TYPE_OBJECT;
452459
$value = serialize($value);

0 commit comments

Comments
 (0)