-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Improve bytes conversion method #7456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@jfsimon, you probably mis-read my comment, the code needs to be reverted. |
@vicb What's wrong with this solution? I need to understand. |
I don't think anybody will ever use a form to upload TB of data, but anyway "t" is not supported (I think the sames goes for "b") |
Okay. What about octal/hexadecimal values? Don't they need to be supported? |
Good point. You should ask @fabpot. |
if (preg_match('#^\s*\+?\s*([0x]*)([1-9][0-9]*)\s*([bkmgt]?)#i', $iniMax, $match)) { | ||
$shift = array('' => 0, 'b' => 0, 'k' => 10, 'm' => 20, 'g' => 30, 't' => 40); | ||
$bases = array('' => 10, '0' => 8, '0x' => 16); | ||
$iniMax = (base_convert($match[2], $bases[$match[1]], 10) * (1 << $shift[strtolower($match[3])])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strtolower
is not needed as the value is already normalized here (upercase)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ìntval
might be better than base_convert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didnt knew intval
, seems better indeed.
Is it ready to be merged? |
@fabpot Yes. |
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
This PR improves bytes conversion
regex
method introduced in #7413 (thanks to @vicb's comments).+
prefix.+
, number and unit.Notice that this can not be unit tested for
ServerParams
andUploadedFile
classes becauseini_set()
function does not work withpost_max_size
andupload_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