Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ea2860

Browse files
enumagfabpot
authored andcommitted
[HttpFoundation] Fix FileBag issue with associative arrays
1 parent 2fc9b57 commit 8ea2860

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Symfony/Component/HttpFoundation/FileBag.php

Lines changed: 4 additions & 1 deletion
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

Lines changed: 15 additions & 2 deletions
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)