Skip to content

Commit b717e36

Browse files
committed
[Form] fixed ServerParams::getPostMaxSize() regex pattern
1 parent d51dcf9 commit b717e36

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

Extension/Validator/Util/ServerParams.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public function getPostMaxSize()
2929
return null;
3030
}
3131

32-
if (preg_match('#^\+?(0x?)?([^kmg]*)([KMG]?)#', $iniMax, $match)) {
32+
if (preg_match('#^\+?(0X?)?([^KMG]*)([KMG]?)#', $iniMax, $match)) {
3333
$shifts = array('' => 0, 'K' => 10, 'M' => 20, 'G' => 30);
34-
$bases = array('' => 10, '0' => 8, '0x' => 16);
34+
$bases = array('' => 10, '0' => 8, '0X' => 16);
3535

3636
return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
3737
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Tests\Extension\Validator\Util;
13+
14+
class ServerParamsTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/** @dataProvider getGetPostMaxSizeTestData */
17+
public function testGetPostMaxSize($size, $bytes)
18+
{
19+
$serverParams = $this->getMock('Symfony\Component\Form\Extension\Validator\Util\ServerParams', array('getNormalizedIniPostMaxSize'));
20+
$serverParams
21+
->expects($this->any())
22+
->method('getNormalizedIniPostMaxSize')
23+
->will($this->returnValue(strtoupper($size)));
24+
25+
$this->assertEquals($bytes, $serverParams->getPostMaxSize());
26+
}
27+
28+
public function getGetPostMaxSizeTestData()
29+
{
30+
return array(
31+
array('2k', 2048),
32+
array('2 k', 2048),
33+
array('+2 k', 2048),
34+
array('+2???k', 2048),
35+
array('0x10', 16),
36+
array('0xf', 15),
37+
array('010', 8),
38+
array('+0x10 k', 16 * 1024),
39+
array('1g', 1024 * 1024 * 1024),
40+
);
41+
}
42+
}

0 commit comments

Comments
 (0)