Skip to content

Commit aece546

Browse files
committed
bug #32485 [Validator] Added support for validation of giga values (kernig)
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
2 parents c03fff5 + 969f2c4 commit aece546

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Symfony/Component/Validator/Constraints/File.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ private function normalizeBinaryFormat($maxSize)
102102
$factors = [
103103
'k' => 1000,
104104
'ki' => 1 << 10,
105-
'm' => 1000000,
105+
'm' => 1000 * 1000,
106106
'mi' => 1 << 20,
107+
'g' => 1000 * 1000 * 1000,
108+
'gi' => 1 << 30,
107109
];
108110
if (ctype_digit((string) $maxSize)) {
109111
$this->maxSize = (int) $maxSize;

src/Symfony/Component/Validator/Tests/Constraints/FileTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public function provideValidSizes()
9797
['1MI', 1048576, true],
9898
['3m', 3000000, false],
9999
['3M', 3000000, false],
100+
['1gi', 1073741824, true],
101+
['1GI', 1073741824, true],
102+
['4g', 4000000000, false],
103+
['4G', 4000000000, false],
100104
];
101105
}
102106

@@ -107,8 +111,6 @@ public function provideInvalidSizes()
107111
['foo'],
108112
['1Ko'],
109113
['1kio'],
110-
['1G'],
111-
['1Gi'],
112114
];
113115
}
114116

0 commit comments

Comments
 (0)