Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed bytes convertion method, again

  • Loading branch information...
commit 233b945f644a2c955b84662659d8e4e078efde1b 1 parent bbb516f
@jfsimon jfsimon authored
View
4 src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php
@@ -29,11 +29,11 @@ public function getPostMaxSize()
return null;
}
- if (preg_match('#^\+?(0X?)?([^KMG]*)([KMG]?)#', $iniMax, $match)) {
+ if (preg_match('#^\+?(0X?)?(.*?)([KMG]?)$#', $iniMax, $match)) {
$shifts = array('' => 0, 'K' => 10, 'M' => 20, 'G' => 30);
$bases = array('' => 10, '0' => 8, '0X' => 16);
- return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
+ return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
}
return 0;
View
4 src/Symfony/Component/Form/Tests/Extension/Validator/Util/ServerParamsTest.php
@@ -30,6 +30,7 @@ public function getGetPostMaxSizeTestData()
return array(
array('2k', 2048),
array('2 k', 2048),
+ array('8m', 8 * 1024 * 1024),
array('+2 k', 2048),
array('+2???k', 2048),
array('0x10', 16),
@@ -37,6 +38,9 @@ public function getGetPostMaxSizeTestData()
array('010', 8),
array('+0x10 k', 16 * 1024),
array('1g', 1024 * 1024 * 1024),
+ array('-1', -1),
+ array('0', 0),
+ array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
);
}
}
View
4 src/Symfony/Component/HttpFoundation/File/UploadedFile.php
@@ -237,11 +237,11 @@ public static function getMaxFilesize()
return PHP_INT_MAX;
}
- if (preg_match('#^\+?(0x?)?([^kmg]*)([kmg]?)#', $max, $match)) {
+ if (preg_match('#^\+?(0x?)?(.*?)([kmg]?)$#', $max, $match)) {
$shifts = array('' => 0, 'k' => 10, 'm' => 20, 'g' => 30);
$bases = array('' => 10, '0' => 8, '0x' => 16);
- return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
+ return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
}
return 0;
View
4 src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php
@@ -79,11 +79,11 @@ private function convertToBytes($memoryLimit)
return -1;
}
- if (preg_match('#^\+?(0x?)?([^kmg]*)([kmg]?)#', $memoryLimit, $match)) {
+ if (preg_match('#^\+?(0x?)?(.*?)([kmg]?)$#', $memoryLimit, $match)) {
$shifts = array('' => 0, 'k' => 10, 'm' => 20, 'g' => 30);
$bases = array('' => 10, '0' => 8, '0x' => 16);
- return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
+ return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
}
return 0;
View
4 src/Symfony/Component/HttpKernel/Tests/DataCollector/MemoryDataCollectorTest.php
@@ -48,6 +48,7 @@ public function getBytesConversionTestData()
return array(
array('2k', 2048),
array('2 k', 2048),
+ array('8m', 8 * 1024 * 1024),
array('+2 k', 2048),
array('+2???k', 2048),
array('0x10', 16),
@@ -55,6 +56,9 @@ public function getBytesConversionTestData()
array('010', 8),
array('+0x10 k', 16 * 1024),
array('1g', 1024 * 1024 * 1024),
+ array('-1', -1),
+ array('0', 0),
+ array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.