Skip to content

Commit

Permalink
bug #32485 [Validator] Added support for validation of giga values (k…
Browse files Browse the repository at this point in the history
…ernig)

This PR was squashed before being merged into the 3.4 branch (closes #32485).

Discussion
----------

[Validator] Added support for validation of giga values

As described in issue #32479

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | just tested on my presta and it works. if further tests are necessary, it would be great if someone could help!
| Fixed tickets | #32479
| License       | MIT
| Doc PR        |

The validation(function normalizeBinaryFormat) in symfony/src/Symfony/Component/Validator/Constraints/File.php doesn't work with gigabyte values in php.ini.
In the PHP documentation it says "PHP allows shortcuts for byte values, including K (kilo), M (mega) and G (giga). " so in my opinion these values should work.
Thanks to @kijamve for the fix.

Commits
-------

969f2c4 [Validator] Added support for validation of giga values
  • Loading branch information
fabpot committed Jul 19, 2019
2 parents c03fff5 + 969f2c4 commit aece546
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Symfony/Component/Validator/Constraints/File.php
Expand Up @@ -102,8 +102,10 @@ private function normalizeBinaryFormat($maxSize)
$factors = [
'k' => 1000,
'ki' => 1 << 10,
'm' => 1000000,
'm' => 1000 * 1000,
'mi' => 1 << 20,
'g' => 1000 * 1000 * 1000,
'gi' => 1 << 30,
];
if (ctype_digit((string) $maxSize)) {
$this->maxSize = (int) $maxSize;
Expand Down
Expand Up @@ -97,6 +97,10 @@ public function provideValidSizes()
['1MI', 1048576, true],
['3m', 3000000, false],
['3M', 3000000, false],
['1gi', 1073741824, true],
['1GI', 1073741824, true],
['4g', 4000000000, false],
['4G', 4000000000, false],
];
}

Expand All @@ -107,8 +111,6 @@ public function provideInvalidSizes()
['foo'],
['1Ko'],
['1kio'],
['1G'],
['1Gi'],
];
}

Expand Down

0 comments on commit aece546

Please sign in to comment.