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