]> git.mxchange.org Git - friendica.git/commitdiff
Check null for acl-fields
authorPhilipp Holzer <admin+github@philipp.info>
Mon, 28 Oct 2019 17:16:10 +0000 (18:16 +0100)
committerPhilipp Holzer <admin+github@philipp.info>
Mon, 28 Oct 2019 17:16:10 +0000 (18:16 +0100)
mod/lockview.php
src/Model/Item.php
src/Module/Item/Compose.php
src/Worker/Notifier.php
tests/src/Util/ACLFormaterTest.php

index 9f9dcfea421beee54a110ccb730cf17eb6ab50ab..af57730c8af68bba0c9f3706f7bde363339964f1 100644 (file)
@@ -64,10 +64,10 @@ function lockview_content(App $a)
        /** @var ACLFormatter $aclFormatter */
        $aclFormatter = BaseObject::getClass(ACLFormatter::class);
 
-       $allowed_users = $aclFormatter->expand($item['allow_cid']);
-       $allowed_groups = $aclFormatter->expand($item['allow_gid']);
-       $deny_users = $aclFormatter->expand($item['deny_cid']);
-       $deny_groups = $aclFormatter->expand($item['deny_gid']);
+       $allowed_users = $aclFormatter->expand($item['allow_cid'] ?? '');
+       $allowed_groups = $aclFormatter->expand($item['allow_gid'] ?? '');
+       $deny_users = $aclFormatter->expand($item['deny_cid'] ?? '');
+       $deny_groups = $aclFormatter->expand($item['deny_gid'] ?? '');
 
        $o = L10n::t('Visible to:') . '<br />';
        $l = [];
index 9501c8e5d240519caed3781703baaa95e3a2e0bf..e298cc1605288a57df3cf1794ce699167f0a9fda 100644 (file)
@@ -2904,10 +2904,10 @@ class Item extends BaseObject
                /** @var ACLFormatter $aclFormater */
                $aclFormater = self::getClass(ACLFormatter::class);
 
-               $allow_people = $aclFormater->expand($obj['allow_cid']);
-               $allow_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['allow_gid']), $check_dead);
-               $deny_people  = $aclFormater->expand($obj['deny_cid']);
-               $deny_groups  = Group::expand($obj['uid'], $aclFormater->expand($obj['deny_gid']), $check_dead);
+               $allow_people = $aclFormater->expand($obj['allow_cid'] ?? '');
+               $allow_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['allow_gid'] ?? ''), $check_dead);
+               $deny_people  = $aclFormater->expand($obj['deny_cid'] ?? '');
+               $deny_groups  = Group::expand($obj['uid'], $aclFormater->expand($obj['deny_gid'] ?? ''), $check_dead);
                $recipients   = array_unique(array_merge($allow_people, $allow_groups));
                $deny         = array_unique(array_merge($deny_people, $deny_groups));
                $recipients   = array_diff($recipients, $deny);
index c44e4c61ab8f66eef3afc77276f43569fa2a9d19..0d3b4eaac226e739eb5ae9e024f913df1430eb97 100644 (file)
@@ -74,8 +74,8 @@ class Compose extends BaseModule
                                $compose_title = L10n::t('Compose new post');
                                $type = 'post';
                                $doesFederate = true;
-                               $contact_allow = implode(',', $aclFormatter->expand($user['allow_cid']));
-                               $group_allow = implode(',', $aclFormatter->expand($user['allow_gid'])) ?: Group::FOLLOWERS;
+                               $contact_allow = implode(',', $aclFormatter->expand($user['allow_cid'] ?? ''));
+                               $group_allow = implode(',', $aclFormatter->expand($user['allow_gid'] ?? '')) ?: Group::FOLLOWERS;
                                break;
                }
 
@@ -86,8 +86,8 @@ class Compose extends BaseModule
                $wall          = $_REQUEST['wall']          ?? $type == 'post';
                $contact_allow = $_REQUEST['contact_allow'] ?? $contact_allow;
                $group_allow   = $_REQUEST['group_allow']   ?? $group_allow;
-               $contact_deny  = $_REQUEST['contact_deny']  ?? implode(',', $aclFormatter->expand($user['deny_cid']));
-               $group_deny    = $_REQUEST['group_deny']    ?? implode(',', $aclFormatter->expand($user['deny_gid']));
+               $contact_deny  = $_REQUEST['contact_deny']  ?? implode(',', $aclFormatter->expand($user['deny_cid'] ?? ''));
+               $group_deny    = $_REQUEST['group_deny']    ?? implode(',', $aclFormatter->expand($user['deny_gid'] ?? ''));
                $visibility    = ($contact_allow . $user['allow_gid'] . $user['deny_cid'] . $user['deny_gid']) ? 'custom' : 'public';
 
                $acl_contacts = Contact::selectToArray(['id', 'name', 'addr', 'micro'], ['uid' => local_user(), 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]);
index ebc70ffb502f3e48f180deda209836b2191d92a7..2b802c9e3caad5e9a4ae6c3a80d97a2754e22170 100644 (file)
@@ -276,10 +276,10 @@ class Notifier
                                /** @var ACLFormatter $aclFormatter */
                                $aclFormatter = BaseObject::getClass(ACLFormatter::class);
 
-                               $allow_people = $aclFormatter->expand($parent['allow_cid']);
-                               $allow_groups = Group::expand($uid, $aclFormatter->expand($parent['allow_gid']),true);
-                               $deny_people  = $aclFormatter->expand($parent['deny_cid']);
-                               $deny_groups  = Group::expand($uid, $aclFormatter->expand($parent['deny_gid']));
+                               $allow_people = $aclFormatter->expand($parent['allow_cid'] ?? '');
+                               $allow_groups = Group::expand($uid, $aclFormatter->expand($parent['allow_gid'] ?? ''),true);
+                               $deny_people  = $aclFormatter->expand($parent['deny_cid'] ?? '');
+                               $deny_groups  = Group::expand($uid, $aclFormatter->expand($parent['deny_gid'] ?? ''));
 
                                // if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
                                // a delivery fork. private groups (forum_mode == 2) do not uplink
index 76a566baaa8e2042f56b2bf534dc343c5866d973..ac5b25e6c26346c6a1e50acba0dd28d969c6490b 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Friendica\Test\src\Util;
 
+use Error;
 use Friendica\Model\Group;
 use Friendica\Util\ACLFormatter;
 use PHPUnit\Framework\TestCase;
@@ -162,6 +163,18 @@ class ACLFormaterTest extends TestCase
                $this->assertEquals(array('1', '3'), $aclFormatter->expand($text));
        }
 
+       /**
+        * Test expected exception in case of wrong typehint
+        *
+        * @expectedException Error
+        */
+       public function testExpandNull()
+       {
+               $aclFormatter = new ACLFormatter();
+
+               $aclFormatter->expand(null);
+       }
+
        public function dataAclToString()
        {
                return [