Skip to content

Commit b0e8d46

Browse files
committed
revert behaviour of sfValidatorSchema::getBytes
1 parent 6f730c0 commit b0e8d46

File tree

2 files changed

+10
-25
lines changed

2 files changed

+10
-25
lines changed

lib/validator/sfValidatorSchema.class.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,14 @@ public function __clone()
390390

391391
protected function getBytes($value)
392392
{
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]);
393+
$value = trim($value);
394+
$number = (float) $value;
395+
$modifier = strtolower($value[strlen($value) - 1]);
397396

398397
$exp_by_modifier = array(
399-
'K' => 1,
400-
'M' => 2,
401-
'G' => 3,
402-
'T' => 4,
403-
'P' => 5,
404-
'E' => 6,
405-
'Z' => 7,
406-
'Y' => 8,
398+
'k' => 1,
399+
'm' => 2,
400+
'g' => 3,
407401
);
408402

409403
if (array_key_exists($modifier, $exp_by_modifier)) {

test/unit/validator/sfValidatorSchemaTest.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
require_once(__DIR__.'/../../bootstrap/unit.php');
1212

13-
$t = new lime_test(103);
13+
$t = new lime_test(94);
1414

1515
class PreValidator extends sfValidatorBase
1616
{
@@ -417,16 +417,7 @@ public function getBytes($value)
417417
$t->is($v->getBytes('0'), 0, 'simple bytes');
418418
$t->is($v->getBytes('1'), 1, 'simple bytes');
419419
$t->is($v->getBytes('1B'), 1, 'simple bytes');
420-
$t->is($v->getBytes('1K'), 1024, 'kilobytes short syntax');
421-
$t->is($v->getBytes('1 K'), 1024, 'kilobytes short syntax with space delimiter');
422-
$t->is($v->getBytes('1KB'), 1024, 'kilobytes long syntax');
423-
$t->is($v->getBytes('1 KB'), 1024, 'kilobytes long syntax with space delimiter');
420+
$t->is($v->getBytes('1K'), 1024, 'kilobytes');
424421
$t->is($v->getBytes('1M'), 1024 * 1024, 'megabytes short syntax');
425-
$t->is($v->getBytes('0.5M'), 1024 * 1024 / 2, 'fractional megabytes short syntax');
426-
$t->is($v->getBytes('0.5 M'), 1024 * 1024 / 2, 'fractional megabytes short syntax with space delimeter');
427-
$t->is($v->getBytes('1 G'), 1024 * 1024 * 1024, 'gigabytes');
428-
$t->is($v->getBytes('1 T'), 1024 * 1024 * 1024 * 1024, 'terabytes');
429-
$t->is($v->getBytes('1 P'), 1024 * 1024 * 1024 * 1024 * 1024, 'petabytes');
430-
$t->is($v->getBytes('1 E'), 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'exabytes');
431-
$t->is($v->getBytes('1 Z'), 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'zettabytes');
432-
$t->is($v->getBytes('1 Y'), 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, 'yottabytes');
422+
$t->is($v->getBytes('0.5M'), 1024 * 1024 / 2, 'fractional megabytes');
423+
$t->is($v->getBytes('1G'), 1024 * 1024 * 1024, 'gigabytes');

0 commit comments

Comments
 (0)