Skip to content

Commit 969f2c4

Browse files
kernigfabpot
authored andcommitted
[Validator] Added support for validation of giga values
1 parent 0349294 commit 969f2c4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

+3-1
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

+4-2
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)