From 233b945f644a2c955b84662659d8e4e078efde1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Wed, 27 Mar 2013 09:25:50 +0100 Subject: [PATCH] fixed bytes convertion method, again --- .../Component/Form/Extension/Validator/Util/ServerParams.php | 4 ++-- .../Form/Tests/Extension/Validator/Util/ServerParamsTest.php | 4 ++++ src/Symfony/Component/HttpFoundation/File/UploadedFile.php | 4 ++-- .../HttpKernel/DataCollector/MemoryDataCollector.php | 4 ++-- .../Tests/DataCollector/MemoryDataCollectorTest.php | 4 ++++ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php b/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php index 42eb7b7473..fab6ac2a61 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php +++ b/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php @@ -29,11 +29,11 @@ class ServerParams 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; diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Util/ServerParamsTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Util/ServerParamsTest.php index e9551df8ed..7ad5b77106 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Util/ServerParamsTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Util/ServerParamsTest.php @@ -30,6 +30,7 @@ class ServerParamsTest extends \PHPUnit_Framework_TestCase 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 @@ class ServerParamsTest extends \PHPUnit_Framework_TestCase 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' ); } } diff --git a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php index f838808582..b6e27a636f 100644 --- a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php +++ b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php @@ -237,11 +237,11 @@ class UploadedFile extends File 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; diff --git a/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php index 3a44680ea6..5540a1b27a 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php @@ -79,11 +79,11 @@ class MemoryDataCollector extends DataCollector 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; diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/MemoryDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/MemoryDataCollectorTest.php index d652b874db..607a580aef 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/MemoryDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/MemoryDataCollectorTest.php @@ -48,6 +48,7 @@ class MemoryDataCollectorTest extends \PHPUnit_Framework_TestCase 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 @@ class MemoryDataCollectorTest extends \PHPUnit_Framework_TestCase 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' ); } }