Merge pull request #8583 from wernerkrauss/fix-8572

Convert::memstring2bytes should return integer value
This commit is contained in:
Robbie Averill 2018-11-07 19:33:40 +02:00 committed by GitHub
commit c3a52099e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 19 deletions

View File

@ -556,7 +556,7 @@ class Convert
* Preserves integer values like "1024" or "-1"
*
* @param string $memString A memory limit string, such as "64M"
* @return float
* @return int
*/
public static function memstring2bytes($memString)
{
@ -568,10 +568,10 @@ class Convert
if ($unit) {
// Find the position of the unit in the ordered string which is the power
// of magnitude to multiply a kilobyte by
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
return (int)round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
}
return round($size);
return (int)round($size);
}
/**

View File

@ -2,12 +2,12 @@
namespace SilverStripe\Core\Tests;
use Exception;
use InvalidArgumentException;
use SilverStripe\Core\Convert;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\Parsers\URLSegmentFilter;
use stdClass;
use Exception;
use InvalidArgumentException;
/**
* Test various functions on the {@link Convert} class.
@ -576,15 +576,15 @@ XML
public function memString2BytesProvider()
{
return [
['-1', (float)-1],
['2048', (float)(2 * 1024)],
['2k', (float)(2 * 1024)],
['512M', (float)(512 * 1024 * 1024)],
['512MiB', (float)(512 * 1024 * 1024)],
['512 mbytes', (float)(512 * 1024 * 1024)],
['512 megabytes', (float)(512 * 1024 * 1024)],
['1024g', (float)(1024 * 1024 * 1024 * 1024)],
['1024G', (float)(1024 * 1024 * 1024 * 1024)]
'infinite' => ['-1', -1],
'integer' => ['2048', 2 * 1024],
'kilo' => ['2k', 2 * 1024],
'mega' => ['512M', 512 * 1024 * 1024],
'MiB' => ['512MiB', 512 * 1024 * 1024],
'mbytes' => ['512 mbytes', 512 * 1024 * 1024],
'megabytes' => ['512 megabytes', 512 * 1024 * 1024],
'giga' => ['1024g', 1024 * 1024 * 1024 * 1024],
'G' => ['1024G', 1024 * 1024 * 1024 * 1024]
];
}
@ -607,11 +607,11 @@ XML
{
return [
[200, '200B'],
[(2 * 1024), '2K'],
[(512 * 1024 * 1024), '512M'],
[(512 * 1024 * 1024 * 1024), '512G'],
[(512 * 1024 * 1024 * 1024 * 1024), '512T'],
[(512 * 1024 * 1024 * 1024 * 1024 * 1024), '512P']
[2 * 1024, '2K'],
[512 * 1024 * 1024, '512M'],
[512 * 1024 * 1024 * 1024, '512G'],
[512 * 1024 * 1024 * 1024 * 1024, '512T'],
[512 * 1024 * 1024 * 1024 * 1024 * 1024, '512P']
];
}
}