Skip to content

Commit

Permalink
Added VCard without FN fallback (sabre-io#384)
Browse files Browse the repository at this point in the history
* Added VCard without FN fallback

see nextcloud/contacts#206

* Added tests for VCard with EMAIL fallback

* Fixed broken test
  • Loading branch information
lars-sh authored and armetiz committed Jun 2, 2020
1 parent 8b1c10f commit 345a04c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/Component/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ function validate($options = 0) {
} elseif (isset($this->ORG)) {
$this->FN = (string)$this->ORG;
$repaired = true;

// Otherwise, the EMAIL property may work
} elseif (isset($this->EMAIL)) {
$this->FN = (string)$this->EMAIL;
$repaired = true;
}

}
Expand Down
9 changes: 8 additions & 1 deletion tests/VObject/Component/VCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ function validateData() {
],
"BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nN:Doe;;;;;;\r\nFN:Doe\r\nEND:VCARD\r\n",
];

// No FN, ORG fallback
$tests[] = [
"BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nORG:Acme Co.\r\nEND:VCARD\r\n",
Expand All @@ -93,6 +92,14 @@ function validateData() {
],
"BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nORG:Acme Co.\r\nFN:Acme Co.\r\nEND:VCARD\r\n",
];
// No FN, EMAIL fallback
$tests[] = [
"BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEMAIL:1@example.org\r\nEND:VCARD\r\n",
[
'The FN property must appear in the VCARD component exactly 1 time',
],
"BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEMAIL:1@example.org\r\nFN:1@example.org\r\nEND:VCARD\r\n",
];
return $tests;

}
Expand Down

0 comments on commit 345a04c

Please sign in to comment.