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
-------
8ea2860996
[HttpFoundation] Fix FileBag issue with associative arrays
This commit is contained in:
commit
d744027357
@ -87,7 +87,10 @@ class FileBag extends ParameterBag
|
|||||||
$file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
|
$file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$file = array_filter(array_map(array($this, 'convertFileInformation'), $file));
|
$file = array_map(array($this, 'convertFileInformation'), $file);
|
||||||
|
if (array_keys($keys) === $keys) {
|
||||||
|
$file = array_filter($file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class FileBagTest extends TestCase
|
|||||||
|
|
||||||
public function testShouldRemoveEmptyUploadedFilesForMultiUpload()
|
public function testShouldRemoveEmptyUploadedFilesForMultiUpload()
|
||||||
{
|
{
|
||||||
$bag = new FileBag(array('file' => array(
|
$bag = new FileBag(array('files' => array(
|
||||||
'name' => array(''),
|
'name' => array(''),
|
||||||
'type' => array(''),
|
'type' => array(''),
|
||||||
'tmp_name' => array(''),
|
'tmp_name' => array(''),
|
||||||
@ -70,7 +70,20 @@ class FileBagTest extends TestCase
|
|||||||
'size' => array(0),
|
'size' => array(0),
|
||||||
)));
|
)));
|
||||||
|
|
||||||
$this->assertSame(array(), $bag->get('file'));
|
$this->assertSame(array(), $bag->get('files'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testShouldNotRemoveEmptyUploadedFilesForAssociativeArray()
|
||||||
|
{
|
||||||
|
$bag = new FileBag(array('files' => array(
|
||||||
|
'name' => array('file1' => ''),
|
||||||
|
'type' => array('file1' => ''),
|
||||||
|
'tmp_name' => array('file1' => ''),
|
||||||
|
'error' => array('file1' => UPLOAD_ERR_NO_FILE),
|
||||||
|
'size' => array('file1' => 0),
|
||||||
|
)));
|
||||||
|
|
||||||
|
$this->assertSame(array('file1' => null), $bag->get('files'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testShouldConvertUploadedFilesWithPhpBug()
|
public function testShouldConvertUploadedFilesWithPhpBug()
|
||||||
|
Reference in New Issue
Block a user