Skip to content

Commit d51dcf9

Browse files
committed
merged branch jfsimon/issue-7413 (PR #7456)
This PR was merged into the master branch. Discussion ---------- Improve bytes conversion method This PR improves bytes conversion `regex` method introduced in #7413 (thanks to @vicb's comments). * Adds support of `+` prefix. * Adds support of blank chars between `+`, number and unit. * Adds support of octal/hexa bases. Notice that this can not be unit tested for `ServerParams` and `UploadedFile` classes because `ini_set()` function does not work with `post_max_size` and `upload_max_filesize` settings. For information, this convertion is located in 3 classes: * `Symfony\Component\Form\Extension\Validator\Util\ServerParams` * `Symfony\Component\HttpFoundation\File\UploadedFile` * `Symfony\Component\HttpKernel\DataCollector\MemoryDataCollector` | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7413 Commits ------- 21291ca improved bytes conversion method
2 parents 05ac0b9 + 8bddfa4 commit d51dcf9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Extension/Validator/Util/ServerParams.php

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

32-
if (preg_match('#^(\d+)([bkmgt])#i', $iniMax, $match)) {
33-
$shift = array('b' => 0, 'k' => 10, 'm' => 20, 'g' => 30, 't' => 40);
34-
$iniMax = ($match[1] * (1 << $shift[strtolower($match[2])]));
32+
if (preg_match('#^\+?(0x?)?([^kmg]*)([KMG]?)#', $iniMax, $match)) {
33+
$shifts = array('' => 0, 'K' => 10, 'M' => 20, 'G' => 30);
34+
$bases = array('' => 10, '0' => 8, '0x' => 16);
35+
36+
return (intval($match[2], $bases[$match[1]]) * (1 << $shifts[$match[3]]));
3537
}
3638

37-
return (int) $iniMax;
39+
return 0;
3840
}
3941

4042
/**

0 commit comments

Comments
 (0)