Skip to content

Commit 95f9fd0

Browse files
committed
fix error "A non well formed numeric value encountered in ... sfValidatorSchema"
1 parent 3ed7f99 commit 95f9fd0

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

lib/validator/sfValidatorSchema.class.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,27 @@ public function __clone()
390390

391391
protected function getBytes($value)
392392
{
393-
$value = trim($value);
394-
switch (strtolower($value[strlen($value) - 1]))
395-
{
396-
// The 'G' modifier is available since PHP 5.1.0
397-
case 'g':
398-
$value *= 1024;
399-
case 'm':
400-
$value *= 1024;
401-
case 'k':
402-
$value *= 1024;
393+
preg_match('/^\s*([0-9.]+(?:E\+\d+)?)\s*([KMGTPEZY]?)B?\s*$/i', $value, $matches);
394+
395+
$number = (float) $matches[1];
396+
$modifier = strtoupper($matches[2]);
397+
398+
$exp_by_modifier = [
399+
'K' => 1,
400+
'M' => 2,
401+
'G' => 3,
402+
'T' => 4,
403+
'P' => 5,
404+
'E' => 6,
405+
'Z' => 7,
406+
'Y' => 8,
407+
];
408+
409+
if (array_key_exists($modifier, $exp_by_modifier)) {
410+
$exp = $exp_by_modifier[$modifier];
411+
$number = $number * pow(1024, $exp);
403412
}
404413

405-
return $value;
414+
return $number;
406415
}
407416
}

0 commit comments

Comments
 (0)