Skip to content

Commit 6444100

Browse files
committed
fixed bytes convertion method, again
1 parent b717e36 commit 6444100

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Extension/Validator/Util/ServerParams.php

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

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

36-
return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
36+
return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
3737
}
3838

3939
return 0;

Tests/Extension/Validator/Util/ServerParamsTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ public function getGetPostMaxSizeTestData()
3030
return array(
3131
array('2k', 2048),
3232
array('2 k', 2048),
33+
array('8m', 8 * 1024 * 1024),
3334
array('+2 k', 2048),
3435
array('+2???k', 2048),
3536
array('0x10', 16),
3637
array('0xf', 15),
3738
array('010', 8),
3839
array('+0x10 k', 16 * 1024),
3940
array('1g', 1024 * 1024 * 1024),
41+
array('-1', -1),
42+
array('0', 0),
43+
array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
4044
);
4145
}
4246
}

0 commit comments

Comments
 (0)