Ensure that "memstring2bytes" can handle if an empty or value with no number is passed in
This commit is contained in:
parent
143b249696
commit
40fa0866ee
|
@ -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
|
||||
|
|
|
@ -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'],
|
||||
|
|
Loading…
Reference in New Issue