Ensure that "memstring2bytes" can handle if an empty or value with no number is passed in

This commit is contained in:
Nick 2021-09-09 00:38:24 +12:00 committed by Guy Sartorelli
parent 143b249696
commit 40fa0866ee
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A
2 changed files with 9 additions and 1 deletions

View File

@ -451,6 +451,10 @@ class Convert
// Remove non-numeric characters from the size
$size = preg_replace('/[^0-9\.\-]/', '', $memString ?? '');
if (empty($size)) {
return 0;
}
if ($unit) {
// Find the position of the unit in the ordered string which is the power
// of magnitude to multiply a kilobyte by

View File

@ -437,7 +437,10 @@ PHP
'mbytes' => ['512 mbytes', 512 * 1024 * 1024],
'megabytes' => ['512 megabytes', 512 * 1024 * 1024],
'giga' => ['1024g', 1024 * 1024 * 1024 * 1024],
'G' => ['1024G', 1024 * 1024 * 1024 * 1024]
'G' => ['1024G', 1024 * 1024 * 1024 * 1024],
'blank' => ['', 0],
'null' => [null, 0],
'no_numbers' => ['k', 0],
];
}
@ -459,6 +462,7 @@ PHP
public function bytes2MemStringProvider()
{
return [
[0, '0B'],
[200, '200B'],
[2 * 1024, '2K'],
[512 * 1024 * 1024, '512M'],