]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Strings.php
Merge pull request #12390 from annando/fixes
[friendica.git] / src / Util / Strings.php
index 5988cc89bcef708f8c3907c890447d3c6677e17b..379f2a25213dda4ed89fc8d688eb4dffb4c038f6 100644 (file)
@@ -23,6 +23,7 @@ namespace Friendica\Util;
 
 use Friendica\Content\ContactSelector;
 use Friendica\Core\Logger;
+use Friendica\Core\System;
 use ParagonIE\ConstantTime\Base64;
 
 /**
@@ -220,7 +221,12 @@ class Strings
         */
        public static function formatBytes(int $bytes, int $precision = 2): string
        {
-               $units = ['B', 'KB', 'MB', 'GB', 'TB'];
+               // If this method is called for an infinite (== unlimited) amount of bytes:
+               if ($bytes == INF) {
+                       return INF;
+               }
+
+               $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
                $bytes = max($bytes, 0);
                $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
                $pow = min($pow, count($units) - 1);
@@ -475,7 +481,7 @@ class Strings
 
                $blocks = [];
 
-               $text = preg_replace_callback($regex,
+               $return = preg_replace_callback($regex,
                        function ($matches) use ($executionId, &$blocks) {
                                $return = '«block-' . $executionId . '-' . count($blocks) . '»';
 
@@ -486,7 +492,11 @@ class Strings
                        $text
                );
 
-               $text = $callback($text) ?? '';
+               if (is_null($return)) {
+                       Logger::warning('Received null value from preg_replace_callback', ['text' => $text, 'regex' => $regex, 'blocks' => $blocks, 'executionId' => $executionId, 'callstack' => System::callstack(10)]);
+               }
+
+               $text = $callback($return ?? $text) ?? '';
 
                // Restore code blocks
                $text = preg_replace_callback('/«block-' . $executionId . '-([0-9]+)»/iU',