From adafd739433981f2a59d676b93407946dd57d47c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Werner=20M=2E=20Krau=C3=9F?= Date: Mon, 5 Nov 2018 17:10:17 +0100 Subject: [PATCH] Convert::memstring2bytes should preserve -1 fixes #8570 --- src/Core/Convert.php | 3 ++- tests/php/Core/ConvertTest.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Core/Convert.php b/src/Core/Convert.php index 7db3ad03d..7c8717724 100644 --- a/src/Core/Convert.php +++ b/src/Core/Convert.php @@ -553,6 +553,7 @@ class Convert /** * Turn a memory string, such as 512M into an actual number of bytes. + * Preserves integer values like "1024" or "-1" * * @param string $memString A memory limit string, such as "64M" * @return float @@ -562,7 +563,7 @@ class Convert // Remove non-unit characters from the size $unit = preg_replace('/[^bkmgtpezy]/i', '', $memString); // Remove non-numeric characters from the size - $size = preg_replace('/[^0-9\.]/', '', $memString); + $size = preg_replace('/[^0-9\.\-]/', '', $memString); if ($unit) { // Find the position of the unit in the ordered string which is the power diff --git a/tests/php/Core/ConvertTest.php b/tests/php/Core/ConvertTest.php index e92f65330..679c611e7 100644 --- a/tests/php/Core/ConvertTest.php +++ b/tests/php/Core/ConvertTest.php @@ -576,6 +576,7 @@ XML public function memString2BytesProvider() { return [ + ['-1', (float)-1], ['2048', (float)(2 * 1024)], ['2k', (float)(2 * 1024)], ['512M', (float)(512 * 1024 * 1024)],