@@ -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