Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3257d4c

Browse filesBrowse files
bug #39633 [HttpFoundation] Drop int return type from parseFilesize() (LukeTowers)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Drop int return type from parseFilesize() | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix [octobercms/october#5410](octobercms/october#5410) | License | MIT | Doc PR | Related: #34516, #34508, 9368502, octobercms/october#5410 Commits ------- a1b31f8 [HttpFoundation] Drop int return type from parseFilesize()
2 parents 732bd84 + a1b31f8 commit 3257d4c
Copy full SHA for 3257d4c

File tree

Expand file treeCollapse file tree

6 files changed

+25
-13
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+25
-13
lines changed

‎.appveyor.yml

Copy file name to clipboardExpand all lines: .appveyor.yml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ install:
2626
- echo memory_limit=-1 >> php.ini-min
2727
- echo serialize_precision=14 >> php.ini-min
2828
- echo max_execution_time=1200 >> php.ini-min
29+
- echo post_max_size=4G >> php.ini-min
30+
- echo upload_max_filesize=4G >> php.ini-min
2931
- echo date.timezone="America/Los_Angeles" >> php.ini-min
3032
- echo extension_dir=ext >> php.ini-min
3133
- echo extension=php_xsl.dll >> php.ini-min

‎src/Symfony/Component/Form/Extension/Core/Type/FileType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/FileType.php
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ private function getFileUploadError(int $errorCode)
178178
* Returns the maximum size of an uploaded file as configured in php.ini.
179179
*
180180
* This method should be kept in sync with Symfony\Component\HttpFoundation\File\UploadedFile::getMaxFilesize().
181+
*
182+
* @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
181183
*/
182-
private static function getMaxFilesize(): int
184+
private static function getMaxFilesize()
183185
{
184186
$iniMax = strtolower(ini_get('upload_max_filesize'));
185187

@@ -214,8 +216,10 @@ private static function getMaxFilesize(): int
214216
* (i.e. try "MB", then "kB", then "bytes").
215217
*
216218
* This method should be kept in sync with Symfony\Component\Validator\Constraints\FileValidator::factorizeSizes().
219+
*
220+
* @param int|float $limit
217221
*/
218-
private function factorizeSizes(int $size, int $limit)
222+
private function factorizeSizes(int $size, $limit)
219223
{
220224
$coef = self::MIB_BYTES;
221225
$coefFactor = self::KIB_BYTES;

‎src/Symfony/Component/HttpFoundation/File/UploadedFile.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/File/UploadedFile.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function move($directory, $name = null)
239239
/**
240240
* Returns the maximum size of an uploaded file as configured in php.ini.
241241
*
242-
* @return int The maximum size of an uploaded file in bytes
242+
* @return int|float The maximum size of an uploaded file in bytes (returns float if size > PHP_INT_MAX)
243243
*/
244244
public static function getMaxFilesize()
245245
{
@@ -251,8 +251,10 @@ public static function getMaxFilesize()
251251

252252
/**
253253
* Returns the given size from an ini value in bytes.
254+
*
255+
* @return int|float Returns float if size > PHP_INT_MAX
254256
*/
255-
private static function parseFilesize($size): int
257+
private static function parseFilesize($size)
256258
{
257259
if ('' === $size) {
258260
return 0;

‎src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/File/UploadedFileTest.php
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\File\Exception\CannotWriteFileException;
1616
use Symfony\Component\HttpFoundation\File\Exception\ExtensionFileException;
1717
use Symfony\Component\HttpFoundation\File\Exception\FileException;
18+
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
1819
use Symfony\Component\HttpFoundation\File\Exception\FormSizeFileException;
1920
use Symfony\Component\HttpFoundation\File\Exception\IniSizeFileException;
2021
use Symfony\Component\HttpFoundation\File\Exception\NoFileException;
@@ -33,7 +34,7 @@ protected function setUp(): void
3334

3435
public function testConstructWhenFileNotExists()
3536
{
36-
$this->expectException(\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException::class);
37+
$this->expectException(FileNotFoundException::class);
3738

3839
new UploadedFile(
3940
__DIR__.'/Fixtures/not_here',
@@ -358,13 +359,16 @@ public function testGetMaxFilesize()
358359
{
359360
$size = UploadedFile::getMaxFilesize();
360361

361-
$this->assertIsInt($size);
362+
if ($size > \PHP_INT_MAX) {
363+
$this->assertIsFloat($size);
364+
} else {
365+
$this->assertIsInt($size);
366+
}
367+
362368
$this->assertGreaterThan(0, $size);
363369

364370
if (0 === (int) ini_get('post_max_size') && 0 === (int) ini_get('upload_max_filesize')) {
365371
$this->assertSame(\PHP_INT_MAX, $size);
366-
} else {
367-
$this->assertLessThan(\PHP_INT_MAX, $size);
368372
}
369373
}
370374
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/FileValidator.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,10 @@ private static function moreDecimalsThan(string $double, int $numberOfDecimals):
214214
/**
215215
* Convert the limit to the smallest possible number
216216
* (i.e. try "MB", then "kB", then "bytes").
217+
*
218+
* @param int|float $limit
217219
*/
218-
private function factorizeSizes(int $size, int $limit, bool $binaryFormat): array
220+
private function factorizeSizes(int $size, $limit, bool $binaryFormat): array
219221
{
220222
if ($binaryFormat) {
221223
$coef = self::MIB_BYTES;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,12 @@ public function uploadedFileErrorProvider()
459459
[, $limit, $suffix] = $method->invokeArgs(new FileValidator(), [0, UploadedFile::getMaxFilesize(), false]);
460460

461461
// it correctly parses the maxSize option and not only uses simple string comparison
462-
// 1000M should be bigger than the ini value
462+
// 1000G should be bigger than the ini value
463463
$tests[] = [(string) \UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', [
464464
'{{ limit }}' => $limit,
465465
'{{ suffix }}' => $suffix,
466-
], '1000M'];
466+
], '1000G'];
467467

468-
// it correctly parses the maxSize option and not only uses simple string comparison
469-
// 1000M should be bigger than the ini value
470468
$tests[] = [(string) \UPLOAD_ERR_INI_SIZE, 'uploadIniSizeErrorMessage', [
471469
'{{ limit }}' => '0.1',
472470
'{{ suffix }}' => 'MB',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.