]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix creating vcards with multiple string values 26865/head
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Fri, 30 Apr 2021 19:36:05 +0000 (21:36 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Mon, 3 May 2021 13:56:02 +0000 (13:56 +0000)
Internally it is valid to provide multiple values for a property as
plain string. An exampe is given in the PhpDoc of
AddressBookImpl::search().

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
apps/dav/lib/CardDAV/AddressBookImpl.php
apps/dav/tests/unit/CardDAV/AddressBookImplTest.php

index a2895fed34a314ed15ef3d6a40585c7adf721382..e270b579e1fa7f2d4925917c915d9430c7a3bed1 100644 (file)
@@ -150,13 +150,17 @@ class AddressBookImpl implements IAddressBook {
                        if (is_array($value)) {
                                $vCard->remove($key);
                                foreach ($value as $entry) {
-                                       if (($key === "ADR" || $key === "PHOTO") && is_string($entry["value"])) {
-                                               $entry["value"] = stripslashes($entry["value"]);
-                                               $entry["value"] = explode(';', $entry["value"]);
-                                       }
-                                       $property = $vCard->createProperty($key, $entry["value"]);
-                                       if (isset($entry["type"])) {
-                                               $property->add('TYPE', $entry["type"]);
+                                       if (is_string($entry)) {
+                                               $property = $vCard->createProperty($key, $entry);
+                                       } else {
+                                               if (($key === "ADR" || $key === "PHOTO") && is_string($entry["value"])) {
+                                                       $entry["value"] = stripslashes($entry["value"]);
+                                                       $entry["value"] = explode(';', $entry["value"]);
+                                               }
+                                               $property = $vCard->createProperty($key, $entry["value"]);
+                                               if (isset($entry["type"])) {
+                                                       $property->add('TYPE', $entry["type"]);
+                                               }
                                        }
                                        $vCard->add($property);
                                }
index 5b28e6b025b7e20c44168af986181921e0cfa6ef..5d037c1f38a697f923a3656904f1073f9400728a 100644 (file)
@@ -154,11 +154,20 @@ class AddressBookImplTest extends TestCase {
                        ->setMethods(['vCard2Array', 'createUid', 'createEmptyVCard'])
                        ->getMock();
 
+               $expectedProperties = 0;
+               foreach ($properties as $data) {
+                       if (is_string($data)) {
+                               $expectedProperties++;
+                       } else {
+                               $expectedProperties += count($data);
+                       }
+               }
+
                $addressBookImpl->expects($this->once())->method('createUid')
                        ->willReturn($uid);
                $addressBookImpl->expects($this->once())->method('createEmptyVCard')
                        ->with($uid)->willReturn($this->vCard);
-               $this->vCard->expects($this->exactly(count($properties)))
+               $this->vCard->expects($this->exactly($expectedProperties))
                        ->method('createProperty');
                $this->backend->expects($this->once())->method('createCard');
                $this->backend->expects($this->never())->method('updateCard');
@@ -172,7 +181,8 @@ class AddressBookImplTest extends TestCase {
        public function dataTestCreate() {
                return [
                        [[]],
-                       [['FN' => 'John Doe']]
+                       [['FN' => 'John Doe']],
+                       [['FN' => 'John Doe', 'EMAIL' => ['john@doe.cloud', 'john.doe@example.org']]],
                ];
        }