Skip to content

Commit

Permalink
[HttpFoundation] Fixed class Request to convert empty files to NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schussek authored and fabpot committed Nov 23, 2010
1 parent f9e830c commit d95d336
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -919,10 +919,12 @@ protected function convertFileInformation(array $files)
$keys = array_keys($data);
sort($keys);

if ($keys == $fileKeys) {
$fixedFiles[$key] = new UploadedFile($data['tmp_name'], $data['name'], $data['type'], $data['size'], $data['error']);
} else {
if ($keys != $fileKeys) {
$fixedFiles[$key] = $this->convertFileInformation($data);
} else if ($data['error'] === UPLOAD_ERR_NO_FILE) {
$fixedFiles[$key] = null;
} else {
$fixedFiles[$key] = new UploadedFile($data['tmp_name'], $data['name'], $data['type'], $data['size'], $data['error']);
}
}
}
Expand All @@ -949,8 +951,8 @@ protected function fixPhpFilesArray($data)
{
if (!is_array($data)) {
return $data;
}
}

$fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
$keys = array_keys($data);
sort($keys);
Expand Down
14 changes: 13 additions & 1 deletion tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php
Expand Up @@ -155,7 +155,6 @@ public function testGetHost()

}


public function testInitializeConvertsUploadedFiles()
{
$tmpFile = $this->createTempFile();
Expand All @@ -172,6 +171,19 @@ public function testInitializeConvertsUploadedFiles()
$this->assertEquals($file, $request->files->get('file'));
}

public function testInitializeDoesNotConvertEmptyUploadedFiles()
{
$request = Request::create('', 'get', array(), array(), array('file' => array(
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => UPLOAD_ERR_NO_FILE,
'size' => 0
)));

$this->assertEquals(null, $request->files->get('file'));
}

public function testInitializeConvertsUploadedFilesWithPhpBug()
{
$tmpFile = $this->createTempFile();
Expand Down

0 comments on commit d95d336

Please sign in to comment.