Skip to content

Commit

Permalink
Merge pull request #26845 from nextcloud/fix/noid/import-card-fix-str…
Browse files Browse the repository at this point in the history
…ing-value

fix creating vcards with multiple string values
  • Loading branch information
MorrisJobke committed May 3, 2021
2 parents 7c3f833 + a9f39aa commit 68c8fa8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
18 changes: 11 additions & 7 deletions apps/dav/lib/CardDAV/AddressBookImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,17 @@ public function createOrUpdate($properties) {
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);
}
Expand Down
14 changes: 12 additions & 2 deletions apps/dav/tests/unit/CardDAV/AddressBookImplTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,20 @@ public function testCreate($properties) {
->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');
Expand All @@ -172,7 +181,8 @@ public function testCreate($properties) {
public function dataTestCreate() {
return [
[[]],
[['FN' => 'John Doe']]
[['FN' => 'John Doe']],
[['FN' => 'John Doe', 'EMAIL' => ['john@doe.cloud', 'john.doe@example.org']]],
];
}

Expand Down

0 comments on commit 68c8fa8

Please sign in to comment.