diff --git a/lib/controller/importcontroller.php b/lib/controller/importcontroller.php index a5be1dc5..c1627112 100644 --- a/lib/controller/importcontroller.php +++ b/lib/controller/importcontroller.php @@ -12,6 +12,7 @@ namespace OCA\Contacts\Controller; use OCA\Contacts\App, OCA\Contacts\JSONResponse, OCA\Contacts\Controller, + OCA\Contacts\VObject\VCard as MyVCard, Sabre\VObject; /** @@ -238,6 +239,13 @@ class ImportController extends Controller { continue; // Ditch cards that can't be parsed by Sabre. } } + try { + $vcard->validate(MyVCard::REPAIR|MyVCard::UPGRADE); + } catch (\Exception $e) { + \OCP\Util::writeLog('contacts', __METHOD__ . ' ' . + 'Error validating vcard: ' . $e->getMessage(), \OCP\Util::ERROR); + $failed += 1; + } /** * TODO * - Check if a contact with identical UID exists. diff --git a/lib/vobject/vcard.php b/lib/vobject/vcard.php index 3ac3ff4e..d81fc25b 100644 --- a/lib/vobject/vcard.php +++ b/lib/vobject/vcard.php @@ -221,17 +221,21 @@ class VCard extends VObject\Component\VCard { } } + $fn = $this->select('FN'); - if (count($fn) !== 1) { + if (count($fn) !== 1 || trim((string)$this->FN) === '') { $warnings[] = array( 'level' => 1, 'message' => 'The FN property must appear in the VCARD component exactly 1 time', 'node' => $this, ); - if (($options & self::REPAIR) && count($fn) === 0) { + if ($options & self::REPAIR) { // We're going to try to see if we can use the contents of the // N property. - if (isset($this->N)) { + if (isset($this->N) + && substr((string)$this->N, 2) !== ';;' + && (string)$this->N !== '' + ) { $value = explode(';', (string)$this->N); if (isset($value[1]) && $value[1]) { $this->FN = $value[1] . ' ' . $value[0];