8000 Format file size in validation message according to binaryFormat option · symfony/symfony@45e5084 · GitHub
[go: up one dir, main page]

Skip to content

Commit 45e5084

Browse files
committed
Format file size in validation message according to binaryFormat option
1 parent 81eb54e commit 45e5084

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function validate($value, Constraint $constraint)
5858
$binaryFormat = $constraint->binaryFormat;
5959
} else {
6060
$limitInBytes = $iniLimitSize;
61-
$binaryFormat = true;
61+
$binaryFormat = null === $constraint->binaryFormat ? true : $constraint->binaryFormat;
6262
}
6363

6464
list($sizeAsString, $limitAsString, $suffix) = $this->factorizeSizes(0, $limitInBytes, $binaryFormat);

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,17 @@ public function uploadedFileErrorProvider()
455455
'{{ suffix }}' => 'bytes',
456456
), '1');
457457

458+
// access FileValidator::factorizeSizes() private method to format max file size
459+
$reflection = new \ReflectionClass(get_class(new FileValidator()));
460+
$method = $reflection->getMethod('factorizeSizes');
461+
$method->setAccessible(true);
462+
list($sizeAsString, $limit, $suffix) = $method->invokeArgs(new FileValidator(), array(0, UploadedFile::getMaxFilesize(), false));
463+
458464
// it correctly parses the maxSize option and not only uses simple string comparison
459465
// 1000M should be bigger than the ini value
460466
$tests[] = array(UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', array(
461-
'{{ limit }}' => UploadedFile::getMaxFilesize() / 1048576,
462-
'{{ suffix }}' => 'MiB',
467+
'{{ limit }}' => $limit,
468+
'{{ suffix }}' => $suffix,
463469
), '1000M');
464470

465471
// it correctly parses the maxSize option and not only uses simple string comparison

0 commit comments

Comments
 (0)
0