From 969f2c4a81d18c3861ec0f6a0c381f962a30f7fd Mon Sep 17 00:00:00 2001 From: kernig Date: Wed, 10 Jul 2019 17:26:36 +0200 Subject: [PATCH] [Validator] Added support for validation of giga values --- src/Symfony/Component/Validator/Constraints/File.php | 4 +++- .../Component/Validator/Tests/Constraints/FileTest.php | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/File.php b/src/Symfony/Component/Validator/Constraints/File.php index 5221857101af..c70db0a74c4c 100644 --- a/src/Symfony/Component/Validator/Constraints/File.php +++ b/src/Symfony/Component/Validator/Constraints/File.php @@ -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; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php index d3117ed44a24..e0b6ec8f41f5 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileTest.php @@ -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], ]; } @@ -107,8 +111,6 @@ public function provideInvalidSizes() ['foo'], ['1Ko'], ['1kio'], - ['1G'], - ['1Gi'], ]; }