]> source.dussan.org Git - nextcloud-server.git/commitdiff
Update ContactsStore: Avoid exceptions on empties 42860/head
authorJosh <josh.t.richards@gmail.com>
Wed, 17 Jan 2024 04:57:58 +0000 (23:57 -0500)
committerGitHub <noreply@github.com>
Wed, 17 Jan 2024 04:57:58 +0000 (23:57 -0500)
Fixes #42858 and makes things more robust

Signed-off-by: Josh <josh.t.richards@gmail.com>
lib/private/Contacts/ContactsMenu/ContactsStore.php

index eeb6ae56bc1e6c35eaa519641d88f7ab8787d784..25a90e5f0f7b37b390920543dedf515a84abe18c 100644 (file)
@@ -334,14 +334,15 @@ class ContactsStore implements IContactsStore {
        private function contactArrayToEntry(array $contact): Entry {
                $entry = new Entry();
 
-               if (isset($contact['UID'])) {
+               if (!empty($contact['UID'])) {
                        $uid = $contact['UID'];
                        $entry->setId($uid);
                        $entry->setProperty('isUser', false);
+                       // overloaded usage so leaving as-is for now
                        if (isset($contact['isLocalSystemBook'])) {
                                $avatar = $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $uid, 'size' => 64]);
                                $entry->setProperty('isUser', true);
-                       } elseif (isset($contact['FN'])) {
+                       } elseif (!empty($contact['FN'])) {
                                $avatar = $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $contact['FN'], 'size' => 64]);
                        } else {
                                $avatar = $this->urlGenerator->linkToRouteAbsolute('core.GuestAvatar.getAvatar', ['guestName' => $uid, 'size' => 64]);
@@ -349,23 +350,23 @@ class ContactsStore implements IContactsStore {
                        $entry->setAvatar($avatar);
                }
 
-               if (isset($contact['FN'])) {
+               if (!empty($contact['FN'])) {
                        $entry->setFullName($contact['FN']);
                }
 
                $avatarPrefix = "VALUE=uri:";
-               if (isset($contact['PHOTO']) && str_starts_with($contact['PHOTO'], $avatarPrefix)) {
+               if (!empty($contact['PHOTO']) && str_starts_with($contact['PHOTO'], $avatarPrefix)) {
                        $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix)));
                }
 
-               if (isset($contact['EMAIL'])) {
+               if (!empty($contact['EMAIL'])) {
                        foreach ($contact['EMAIL'] as $email) {
                                $entry->addEMailAddress($email);
                        }
                }
 
                // Provide profile parameters for core/src/OC/contactsmenu/contact.handlebars template
-               if (isset($contact['UID']) && isset($contact['FN'])) {
+               if (!empty($contact['UID']) && !empty($contact['FN'])) {
                        $targetUserId = $contact['UID'];
                        $targetUser = $this->userManager->get($targetUserId);
                        if (!empty($targetUser)) {