8000 [HttpFoundation] Fix FileBag issue with associative arrays by enumag · Pull Request #24606 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] Fix FileBag issue with associative arrays #24606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

< 8000 div class="position-relative diffbar-item ml-0">
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[HttpFoundation] Fix FileBag issue with associative arrays
  • Loading branch information
enumag committed Oct 18, 2017
commit 72700326a3d95227204f65669f1dacb621ef0b58
5 changes: 4 additions & 1 deletion src/Symfony/Component/HttpFoundation/FileBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ protected function convertFileInformation($file)
$file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
}
} 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);
}
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,28 @@ public function testShouldSetEmptyUploadedFilesToNull()

public function testShouldRemoveEmptyUploadedFilesForMultiUpload()
{
$bag = new FileBag(array('file' => array(
$bag = new FileBag(array('files' => array(
'name' => array(''),
'type' => array(''),
'tmp_name' => array(''),
'error' => array(UPLOAD_ERR_NO_FILE),
'size' => array(0),
)));

$this->assertSame(array(), $bag->get('file'));
$this->assertSame(array(), $bag->get('files'));
}

public function testNotShouldRemoveEmptyUploadedFilesForAssociativeArray()
{
$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()
Expand Down
0