Skip to content

[Validator] Improve FileValidator sizes factorization edge case #45093

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

Merged
merged 1 commit into from
Apr 12, 2022

Conversation

fancyweb
Copy link
Contributor

Q A
Branch? 6.1
Bug fix? no
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -
new File(maxSize: '100k'); // 100_000 bytes

Uploading a 169_630 bytes files (169.63 KB), I get:

The file is too large (0.17 MB). Allowed maximum size is 0.1 MB.

Displaying an allowed maximum size in MB while the maximum I specified is lower than 1 MB is not optimal IMO.

Most of the time the problem doesn't occur because the first division result in FileValidator::factorizeSizes() is a number < 1 but it has more than 2 decimals, so it's still go in the "while" loop. It's visible only with specific values, when the division result "tombe juste 🇫🇷".

For example, If I change the maximum allowed size a bit:

new File(maxSize: '101k'); // 101_000 bytes

I get:

The file is too large (169.63 kB). Allowed maximum size is 101 kB.

@fancyweb fancyweb force-pushed the validator/file-factorize branch 2 times, most recently from e3e7ca1 to 27d0494 Compare January 26, 2022 17:41
@fancyweb fancyweb force-pushed the validator/file-factorize branch from 27d0494 to e95fd72 Compare February 24, 2022 15:28
@fancyweb fancyweb force-pushed the validator/file-factorize branch from e95fd72 to 054295a Compare March 28, 2022 08:48
@fancyweb fancyweb force-pushed the validator/file-factorize branch from 054295a to 6f9fdaa Compare April 12, 2022 09:48
@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

@nicolas-grekas nicolas-grekas merged commit 6299015 into symfony:6.1 Apr 12, 2022
@fancyweb fancyweb deleted the validator/file-factorize branch April 12, 2022 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants