diff options
author | Morris Jobke <hey@morrisjobke.de> | 2021-05-03 15:49:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-03 15:49:43 +0200 |
commit | 68c8fa8235094e84dbee978b6dc73c2c9034ea12 (patch) | |
tree | ce1835811389cfabaca1b1c90fd5fbc293acf515 /apps/dav | |
parent | 7c3f8331ef560468fa4576cf19c7ceec94257389 (diff) | |
parent | a9f39aab29f1d08c58c6b3ef87f461c29740bf19 (diff) | |
download | nextcloud-server-68c8fa8235094e84dbee978b6dc73c2c9034ea12.tar.gz nextcloud-server-68c8fa8235094e84dbee978b6dc73c2c9034ea12.zip |
Merge pull request #26845 from nextcloud/fix/noid/import-card-fix-string-value
fix creating vcards with multiple string values
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/CardDAV/AddressBookImpl.php | 18 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/AddressBookImplTest.php | 14 |
2 files changed, 23 insertions, 9 deletions
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php index a2895fed34a..e270b579e1f 100644 --- a/apps/dav/lib/CardDAV/AddressBookImpl.php +++ b/apps/dav/lib/CardDAV/AddressBookImpl.php @@ -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); } diff --git a/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php b/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php index 85be3a4bfb5..38d560b9539 100644 --- a/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php +++ b/apps/dav/tests/unit/CardDAV/AddressBookImplTest.php @@ -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']]], ]; } |