8000 merged branch jfsimon/issue-7481 (PR #7489) · symfony/symfony@ea79360 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea79360

Browse files
committed
merged branch jfsimon/issue-7481 (PR #7489)
This PR was merged into the master branch. Discussion ---------- Fixes bytes convertion method, last episode This definitely fixes the bytes convertion method. @lazyhammer thanks for your support & indulgence @fabpot sorry for the running gag @vicb I opened a ticket: https://bugs.php.net/bug.php?id=64530 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7481 Commits ------- 233b945 fixed bytes convertion method, again
2 parents bbb516f + 233b945 commit ea79360

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

src/Symfony/Component/Form/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;

src/Symfony/Component/Form/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
}

src/Symfony/Component/HttpFoundation/File/UploadedFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ public static function getMaxFilesize()
237237
return PHP_INT_MAX;
238238
}
239239

240-
if (preg_match('#^\+?(0x?)?([^kmg]*)([kmg]?)#', $max, $match)) {
240+
if (preg_match('#^\+?(0x?)?(.*?)([kmg]?)$#', $max, $match)) {
241241
$shifts = array('' => 0, 'k' => 10, 'm' => 20, 'g' => 30);
242242
$bases = array('' => 10, '0' => 8, '0x' => 16);
243243

244-
return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
244+
return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
245245
}
246246

247247
return 0;

src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ private function convertToBytes($memoryLimit)
7979
return -1;
8080
}
8181

82-
if (preg_match('#^\+?(0x?)?([^kmg]*)([kmg]?)#', $memoryLimit, $match)) {
82+
if (preg_match('#^\+?(0x?)?(.*?)([kmg]?)$#', $memoryLimit, $match)) {
8383
$shifts = array('' => 0, 'k' => 10, 'm' => 20, 'g' => 30);
8484
$bases = array('' => 10, '0' => 8, '0x' => 16);
8585

86-
return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
86+
return intval($match[2], $bases[$match[1]]) << $shifts[$match[3]];
8787
}
8888

8989
return 0;

src/Symfony/Component/HttpKernel/Tests/DataCollector/MemoryDataCollectorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ public function getBytesConversionTestData()
4848
return array(
4949
array('2k', 2048),
5050
array('2 k', 2048),
51+
array('8m', 8 * 1024 * 1024),
5152
array('+2 k', 2048),
5253
array('+2???k', 2048),
5354
array('0x10', 16),
5455
array('0xf', 15),
5556
array('010', 8),
5657
array('+0x10 k', 16 * 1024),
5758
array('1g', 1024 * 1024 * 1024),
59+
array('-1', -1),
60+
array('0', 0),
61+
array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
5862
);
5963
}
6064
}

0 commit comments

Comments
 (0)
0