Skip to content

Commit

Permalink
bug #42112 [HttpFoundation] fix FileBag under PHP 8.1 (alexpott)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

[HttpFoundation] fix FileBag under PHP 8.1

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| 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 #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

See https://php.watch/versions/8.1/$_FILES-full-path - in \Symfony\Component\HttpFoundation\FileBag::convertFileInformation() we check against a list of hardcoded keys. This logic breaks in PHP 8.1 because of the new key.

Commits
-------

dc3504989b [HttpFoundation] fix FileBag under PHP 8.1
  • Loading branch information
derrabus committed Jul 15, 2021
2 parents c087ba3 + 17a1c3d commit c4d9e00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions FileBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ protected function convertFileInformation($file)
*/
protected function fixPhpFilesArray($data)
{
// Remove extra key added by PHP 8.1.
unset($data['full_path']);
$keys = array_keys($data);
sort($keys);

Expand Down
17 changes: 17 additions & 0 deletions Tests/FileBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ public function testShouldConvertsUploadedFiles()
$this->assertEquals($file, $bag->get('file'));
}

public function testShouldConvertsUploadedFilesPhp81()
{
$tmpFile = $this->createTempFile();
$file = new UploadedFile($tmpFile, basename($tmpFile), 'text/plain');

$bag = new FileBag(['file' => [
'name' => basename($tmpFile),
'full_path' => basename($tmpFile),
'type' => 'text/plain',
'tmp_name' => $tmpFile,
'error' => 0,
'size' => null,
]]);

$this->assertEquals($file, $bag->get('file'));
}

public function testShouldSetEmptyUploadedFilesToNull()
{
$bag = new FileBag(['file' => [
Expand Down

0 comments on commit c4d9e00

Please sign in to comment.