Skip to content

Commit d744027

Browse files
committed
bug #24606 [HttpFoundation] Fix FileBag issue with associative arrays (enumag)
This PR was squashed before being merged into the 2.7 branch (closes #24606). Discussion ---------- [HttpFoundation] Fix FileBag issue with associative arrays | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24546 | License | MIT | Doc PR | Commits ------- 8ea2860 [HttpFoundation] Fix FileBag issue with associative arrays
2 parents b0cf42b + 8ea2860 commit d744027

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Symfony/Component/HttpFoundation/FileBag.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ protected function convertFileInformation($file)
8787
$file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
8888
}
8989
} else {
90-
$file = array_filter(array_map(array($this, 'convertFileInformation'), $file));
90+
$file = array_map(array($this, 'convertFileInformation'), $file);
91+
if (array_keys($keys) === $keys) {
92+
$file = array_filter($file);
93+
}
9194
}
9295
}
9396

src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,28 @@ public function testShouldSetEmptyUploadedFilesToNull()
6262

6363
public function testShouldRemoveEmptyUploadedFilesForMultiUpload()
6464
{
65-
$bag = new FileBag(array('file' => array(
65+
$bag = new FileBag(array('files' => array(
6666
'name' => array(''),
6767
'type' => array(''),
6868
'tmp_name' => array(''),
6969
'error' => array(UPLOAD_ERR_NO_FILE),
7070
'size' => array(0),
7171
)));
7272

73-
$this->assertSame(array(), $bag->get('file'));
73+
$this->assertSame(array(), $bag->get('files'));
74+
}
75+
76+
public function testShouldNotRemoveEmptyUploadedFilesForAssociativeArray()
77+
{
78+
$bag = new FileBag(array('files' => array(
79+
'name' => array('file1' => ''),
80+
'type' => array('file1' => ''),
81+
'tmp_name' => array('file1' => ''),
82+
'error' => array('file1' => UPLOAD_ERR_NO_FILE),
83+
'size' => array('file1' => 0),
84+
)));
85+
86+
$this->assertSame(array('file1' => null), $bag->get('files'));
7487
}
7588

7689
public function testShouldConvertUploadedFilesWithPhpBug()

0 commit comments

Comments
 (0)