From 1aa874e8d3f2d7cb0ff9631cec7de55b907b0d96 Mon Sep 17 00:00:00 2001 From: Alexey Shpakovsky Date: Thu, 3 Jun 2021 21:14:46 +0200 Subject: [PATCH] properly return empty array if nothing was found in lookup --- abook_class.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/abook_class.php b/abook_class.php index 2c47f08..06342ca 100755 --- a/abook_class.php +++ b/abook_class.php @@ -168,23 +168,26 @@ class abook_carddav extends addressbook_backend { */ function lookup($value, $field=SM_ABOOK_FIELD_NICKNAME) { - if (empty($value)) { - return array(); - } + if (empty($value)) { return array(); } $abook_uri_len=strlen($this->abook->getUriPath()); if($field == SM_ABOOK_FIELD_NICKNAME) { // TODO: edit this if we use different nick-naming scheme $uri = $this->abook->getUriPath() . $value; - $one = $this->abook->getCard($uri); - /* returns Associative array with keys: - etag(string): Entity tag of the returned card - vcf(string): VCard as string - vcard(VCard): VCard as Sabre/VObject VCard - */ - $vcard = $one['vcard']; - // TODO: verify that something was returned - return $this->vcard2sq($uri, $vcard); + try { + $one = $this->abook->getCard($uri); + /* returns Associative array with keys: + etag(string): Entity tag of the returned card + vcf(string): VCard as string + vcard(VCard): VCard as Sabre/VObject VCard + */ + $vcard = $one['vcard']; + return $this->vcard2sq($uri, $vcard); + } catch (\Exception $e) { + // no card was returned + return array(); + } + } if($field == SM_ABOOK_FIELD_FIRSTNAME) { } // TODO: this will be harder if($field == SM_ABOOK_FIELD_LASTNAME) { $filter=['N' => "/$value;/^", 'EMAIL' => "//"]; }