From 84541e7a74bc895971864150634b34cce2b80052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Tue, 26 Mar 2013 13:30:34 +0100 Subject: [PATCH] [Form] fixed ServerParams::getPostMaxSize() regex pattern --- .../Extension/Validator/Util/ServerParams.php | 4 +- .../Validator/Util/ServerParamsTest.php | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/Form/Tests/Extension/Validator/Util/ServerParamsTest.php diff --git a/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php b/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php index f7f48e3357..42eb7b7473 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php +++ b/src/Symfony/Component/Form/Extension/Validator/Util/ServerParams.php @@ -29,9 +29,9 @@ class ServerParams return null; } - if (preg_match('#^\+?(0x?)?([^kmg]*)([KMG]?)#', $iniMax, $match)) { + if (preg_match('#^\+?(0X?)?([^KMG]*)([KMG]?)#', $iniMax, $match)) { $shifts = array('' => 0, 'K' => 10, 'M' => 20, 'G' => 30); - $bases = array('' => 10, '0' => 8, '0x' => 16); + $bases = array('' => 10, '0' => 8, '0X' => 16); return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]])); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Util/ServerParamsTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Util/ServerParamsTest.php new file mode 100644 index 0000000000..e9551df8ed --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Util/ServerParamsTest.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Form\Tests\Extension\Validator\Util; + +class ServerParamsTest extends \PHPUnit_Framework_TestCase +{ + /** @dataProvider getGetPostMaxSizeTestData */ + public function testGetPostMaxSize($size, $bytes) + { + $serverParams = $this->getMock('Symfony\Component\Form\Extension\Validator\Util\ServerParams', array('getNormalizedIniPostMaxSize')); + $serverParams + ->expects($this->any()) + ->method('getNormalizedIniPostMaxSize') + ->will($this->returnValue(strtoupper($size))); + + $this->assertEquals($bytes, $serverParams->getPostMaxSize()); + } + + public function getGetPostMaxSizeTestData() + { + return array( + array('2k', 2048), + array('2 k', 2048), + array('+2 k', 2048), + array('+2???k', 2048), + array('0x10', 16), + array('0xf', 15), + array('010', 8), + array('+0x10 k', 16 * 1024), + array('1g', 1024 * 1024 * 1024), + ); + } +}