]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7208 from nupplaphil/bug/6916-filetag
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 31 May 2019 05:47:52 +0000 (01:47 -0400)
committerGitHub <noreply@github.com>
Fri, 31 May 2019 05:47:52 +0000 (01:47 -0400)
Adding null checks before FileTag method (fix fatal)

mod/notifications.php
mod/parse_url.php
mod/photos.php
mod/redir.php
src/Model/Item.php
src/Module/Admin/Federation.php
src/Protocol/Diaspora.php
src/Util/Strings.php
tests/src/Util/StringsTest.php

index ff954d4189250cba0cf88ccf33f01ade71ed9f35..8bc9a76c388efcaef89d1c787579d6a68a047700 100644 (file)
@@ -121,6 +121,9 @@ function notifications_content(App $a)
        } elseif (($a->argc > 1) && ($a->argv[1] == 'home')) {
                $notif_header = L10n::t('Home Notifications');
                $notifs = $nm->homeNotifs($show, $startrec, $perpage);
+       // fallback - redirect to main page
+       } else {
+               $a->internalRedirect('notifications');
        }
 
        // Set the pager
index 3b2522ab12fb05184bcd4f54f1af6a85ebbc2c00..7631a5a710b62d07d0f349b2b3b17914debb81a6 100644 (file)
@@ -9,12 +9,14 @@
  *
  * @see ParseUrl::getSiteinfo() for more information about scraping embeddable content
  */
+
 use Friendica\App;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
+use Friendica\Util\Strings;
 
 function parse_url_content(App $a)
 {
@@ -25,10 +27,14 @@ function parse_url_content(App $a)
 
        $br = "\n";
 
-       if (!empty($_GET['binurl'])) {
+       if (!empty($_GET['binurl']) && Strings::isHex($_GET['binurl'])) {
                $url = trim(hex2bin($_GET['binurl']));
-       } else {
+       } elseif (!empty($_GET['url'])) {
                $url = trim($_GET['url']);
+       // fallback in case no url is valid
+       } else {
+               Logger::info('No url given');
+               exit();
        }
 
        if (!empty($_GET['title'])) {
index b18c06e2a3a4e5bf4b410f47b1a83f3c910b1245..b904abe311da1f428c22182dd36b89b6a6033430 100644 (file)
@@ -188,6 +188,9 @@ function photos_post(App $a)
        }
 
        if ($a->argc > 3 && $a->argv[2] === 'album') {
+               if (!Strings::isHex($a->argv[3])) {
+                       $a->internalRedirect('photos/' . $a->data['user']['nickname'] . '/album');
+               }
                $album = hex2bin($a->argv[3]);
 
                if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
@@ -960,7 +963,7 @@ function photos_content(App $a)
                        return;
                }
 
-               $selname = $datum ? hex2bin($datum) : '';
+               $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
 
                $albumselect = '';
 
@@ -1027,6 +1030,10 @@ function photos_content(App $a)
 
        // Display a single photo album
        if ($datatype === 'album') {
+               // if $datum is not a valid hex, redirect to the default page
+               if (!Strings::isHex($datum)) {
+                       $a->internalRedirect('photos/' . $a->data['user']['nickname']. '/album');
+               }
                $album = hex2bin($datum);
 
                $total = 0;
@@ -1504,7 +1511,7 @@ function photos_content(App $a)
                                                '$title' => $title_e,
                                                '$body' => $body_e,
                                                '$ago' => Temporal::getRelativeDate($item['created']),
-                                               '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
+                                               '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
                                                '$drop' => $drop,
                                                '$comment' => $comment
                                        ]);
@@ -1513,7 +1520,7 @@ function photos_content(App $a)
                                                $comments .= Renderer::replaceMacros($cmnt_tpl, [
                                                        '$return_path' => '',
                                                        '$jsreload' => $return_path,
-                                                       '$id' => $item['item_id'],
+                                                       '$id' => $item['id'],
                                                        '$parent' => $item['parent'],
                                                        '$profile_uid' =>  $owner_uid,
                                                        '$mylink' => $contact['url'],
index 4dbae5498b38f24079f75507f61fc8e70fce1a6a..233ec9b0079ff59a65d2b033eeda318f836ebd31 100644 (file)
@@ -3,12 +3,13 @@
 use Friendica\App;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
+use Friendica\Core\Session;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Profile;
-use Friendica\Util\Strings;
 use Friendica\Util\Network;
+use Friendica\Util\Strings;
 
 function redir_init(App $a) {
 
@@ -70,7 +71,9 @@ function redir_init(App $a) {
                                && is_array($_SESSION['remote']))
                        {
                                foreach ($_SESSION['remote'] as $v) {
-                                       if ($v['uid'] == $_SESSION['visitor_visiting'] && $v['cid'] == $_SESSION['visitor_id']) {
+                                       if (!empty($v['uid']) && !empty($v['cid']) &&
+                                           $v['uid'] == Session::get('visitor_visiting') &&
+                                           $v['cid'] == Session::get('visitor_id')) {
                                                // Remote user is already authenticated.
                                                $target_url = defaults($url, $contact_url);
                                                Logger::log($contact['name'] . " is already authenticated. Redirecting to " . $target_url, Logger::DEBUG);
index a01ff61143f06a461060fe55503be35da69dd8f3..8ae412cd0a7d2fa7f1f416e76b424d36680ec01b 100644 (file)
@@ -11,9 +11,9 @@ use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
 use Friendica\Core\Config;
 use Friendica\Core\Hook;
+use Friendica\Core\L10n;
 use Friendica\Core\Lock;
 use Friendica\Core\Logger;
-use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
@@ -24,10 +24,10 @@ use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Map;
-use Friendica\Util\XML;
+use Friendica\Util\Network;
 use Friendica\Util\Security;
 use Friendica\Util\Strings;
-use Friendica\Util\Network;
+use Friendica\Util\XML;
 use Text_LanguageDetect;
 
 class Item extends BaseObject
@@ -87,7 +87,7 @@ class Item extends BaseObject
                        'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network',
                        'title', 'content-warning', 'body', 'location', 'coord', 'app',
                        'rendered-hash', 'rendered-html', 'object-type', 'object', 'target-type', 'target',
-                       'author-id', 'author-link', 'author-name', 'author-avatar',
+                       'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
                        'owner-id', 'owner-link', 'owner-name', 'owner-avatar'];
 
        // Never reorder or remove entries from this list. Just add new ones at the end, if needed.
@@ -1721,6 +1721,7 @@ class Item extends BaseObject
                unset($item['author-link']);
                unset($item['author-name']);
                unset($item['author-avatar']);
+               unset($item['author-network']);
 
                unset($item['owner-link']);
                unset($item['owner-name']);
index f32f0e2ccd6f15dcbcf2db0f16385c1804d14104..9c52845b93094f3c7a8c8e654701fc6bc2c4defb 100644 (file)
@@ -87,7 +87,9 @@ class Federation extends BaseAdminModule
                                                $part = array_pop($parts);
                                        } while (!empty($parts) && ((strlen($part) >= 40) || (strlen($part) <= 3)));
                                        // only take the x.x.x part of the version, not the "release" after the dash
-                                       $part = array_shift(explode('-', $part));
+                                       if (!empty($part) && strpos($part, '-')) {
+                                               $part = array_shift(explode('-', $part));
+                                       }
                                        if (!empty($part)) {
                                                if (empty($compacted[$part])) {
                                                        $compacted[$part] = $versionCounts[$key]['total'];
index 98b0d4d3ded25040de91d757c8e9737ec7a4deb8..818f078bb103103c7161a1063dd2057d169fd8e4 100644 (file)
@@ -3562,6 +3562,7 @@ class Diaspora
                $public = ($item["private"] ? "false" : "true");
 
                $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
+               $edited = DateTimeFormat::utc($item["edited"], DateTimeFormat::ATOM);
 
                // Detect a share element and do a reshare
                if (!$item['private'] && ($ret = self::isReshare($item["body"]))) {
@@ -3616,6 +3617,7 @@ class Diaspora
                        $message = ["author" => $myaddr,
                                        "guid" => $item["guid"],
                                        "created_at" => $created,
+                                       "edited_at" => $edited,
                                        "public" => $public,
                                        "text" => $body,
                                        "provider_display_name" => $item["app"],
@@ -3794,11 +3796,13 @@ class Diaspora
 
                $text = html_entity_decode(BBCode::toMarkdown($body));
                $created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
+               $edited = DateTimeFormat::utc($item["edited"], DateTimeFormat::ATOM);
 
                $comment = [
                        "author"      => self::myHandle($owner),
                        "guid"        => $item["guid"],
                        "created_at"  => $created,
+                       "edited_at"   => $edited,
                        "parent_guid" => $toplevel_item["guid"],
                        "text"        => $text,
                        "author_signature" => ""
index 3f8990d6c124ee268b0de9b10becd1e35adba9d5..88dd1d39f81edd151151dac1ba6b7449528dd871 100644 (file)
@@ -31,6 +31,18 @@ class Strings
         return $return;
     }
 
+       /**
+        * Checks, if the given string is a valid hexadecimal code
+        *
+        * @param string $hexCode
+        *
+        * @return bool
+        */
+    public static function isHex($hexCode)
+    {
+           return !empty($hexCode) ? @preg_match("/^[a-f0-9]{2,}$/i", $hexCode) && !(strlen($hexCode) & 1) : false;
+    }
+
     /**
      * @brief This is our primary input filter.
      *
index 666b76e57b1c225bd2c6348e42a530bc3a690075..f926183108c1e71634414bd80397788279d36f11 100644 (file)
@@ -82,4 +82,39 @@ class StringsTest extends TestCase
                        $escapedString
                );
        }
+
+       public function dataIsHex()
+       {
+               return [
+                       'validHex' => [
+                               'input' => '90913473615bf00c122ac78338492980',
+                               'valid' => true,
+                       ],
+                       'invalidHex' => [
+                               'input' => '90913473615bf00c122ac7833849293',
+                               'valid' => false,
+                       ],
+                       'emptyHex' => [
+                               'input' => '',
+                               'valid' => false,
+                       ],
+                       'nullHex' => [
+                               'input' => null,
+                               'valid' => false,
+                       ],
+               ];
+       }
+
+       /**
+        * Tests if the string is a valid hexadecimal value
+        *
+        * @param string $input
+        * @param bool $valid
+        *
+        * @dataProvider dataIsHex
+        */
+       public function testIsHex($input, $valid)
+       {
+               $this->assertEquals($valid, Strings::isHex($input));
+       }
 }