bug #13769 [Form] NativeRequestHandler file handling fix (mpajunen)
This PR was squashed before being merged into the 2.3 branch (closes #13769).
Discussion
----------
[Form] NativeRequestHandler file handling fix
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #13746
| License | MIT
| Doc PR | n/a
`NativeRequestHandler` reused the local variable for the form name `$name` as a loop variable for processing the `$_FILES` array. A separate variable is now used.
Two new test cases are included:
- Handling a request with multiple files
- Handling a request with file upload and a nameless form
Both tests fail without the fix. The test cases could probably be better though.
Commits
-------
9b3421f
[Form] NativeRequestHandler file handling fix
This commit is contained in:
commit
ab7b3a8119
@ -98,8 +98,8 @@ class NativeRequestHandler implements RequestHandlerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$fixedFiles = array();
|
$fixedFiles = array();
|
||||||
foreach ($_FILES as $name => $file) {
|
foreach ($_FILES as $fileKey => $file) {
|
||||||
$fixedFiles[$name] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
|
$fixedFiles[$fileKey] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' === $name) {
|
if ('' === $name) {
|
||||||
|
@ -266,6 +266,50 @@ abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->requestHandler->handleRequest($form, $this->request);
|
$this->requestHandler->handleRequest($form, $this->request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider methodExceptGetProvider
|
||||||
|
*/
|
||||||
|
public function testSubmitMultipleFiles($method)
|
||||||
|
{
|
||||||
|
$form = $this->getMockForm('param1', $method);
|
||||||
|
$file = $this->getMockFile();
|
||||||
|
|
||||||
|
$this->setRequestData($method, array(
|
||||||
|
'param1' => null,
|
||||||
|
), array(
|
||||||
|
'param2' => $this->getMockFile('2'),
|
||||||
|
'param1' => $file,
|
||||||
|
'param3' => $this->getMockFile('3'),
|
||||||
|
));
|
||||||
|
|
||||||
|
$form->expects($this->once())
|
||||||
|
->method('submit')
|
||||||
|
->with($file, 'PATCH' !== $method);
|
||||||
|
|
||||||
|
$this->requestHandler->handleRequest($form, $this->request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider methodExceptGetProvider
|
||||||
|
*/
|
||||||
|
public function testSubmitFileWithNamelessForm($method)
|
||||||
|
{
|
||||||
|
$form = $this->getMockForm(null, $method);
|
||||||
|
$file = $this->getMockFile();
|
||||||
|
|
||||||
|
$this->setRequestData($method, array(
|
||||||
|
'' => null,
|
||||||
|
), array(
|
||||||
|
'' => $file,
|
||||||
|
));
|
||||||
|
|
||||||
|
$form->expects($this->once())
|
||||||
|
->method('submit')
|
||||||
|
->with($file, 'PATCH' !== $method);
|
||||||
|
|
||||||
|
$this->requestHandler->handleRequest($form, $this->request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider getPostMaxSizeFixtures
|
* @dataProvider getPostMaxSizeFixtures
|
||||||
*/
|
*/
|
||||||
@ -314,7 +358,7 @@ abstract class AbstractRequestHandlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
abstract protected function getRequestHandler();
|
abstract protected function getRequestHandler();
|
||||||
|
|
||||||
abstract protected function getMockFile();
|
abstract protected function getMockFile($suffix = '');
|
||||||
|
|
||||||
protected function getMockForm($name, $method = null, $compound = true)
|
protected function getMockForm($name, $method = null, $compound = true)
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,8 @@ class HttpFoundationRequestHandlerTest extends AbstractRequestHandlerTest
|
|||||||
return new HttpFoundationRequestHandler($this->serverParams);
|
return new HttpFoundationRequestHandler($this->serverParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getMockFile()
|
protected function getMockFile($suffix = '')
|
||||||
{
|
{
|
||||||
return new UploadedFile(__DIR__.'/../../Fixtures/foo', 'foo');
|
return new UploadedFile(__DIR__.'/../../Fixtures/foo'.$suffix, 'foo'.$suffix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
0
src/Symfony/Component/Form/Tests/Fixtures/foo2
Normal file
0
src/Symfony/Component/Form/Tests/Fixtures/foo2
Normal file
0
src/Symfony/Component/Form/Tests/Fixtures/foo3
Normal file
0
src/Symfony/Component/Form/Tests/Fixtures/foo3
Normal file
@ -206,12 +206,12 @@ class NativeRequestHandlerTest extends AbstractRequestHandlerTest
|
|||||||
return new NativeRequestHandler($this->serverParams);
|
return new NativeRequestHandler($this->serverParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getMockFile()
|
protected function getMockFile($suffix = '')
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'name' => 'upload.txt',
|
'name' => 'upload'.$suffix.'.txt',
|
||||||
'type' => 'text/plain',
|
'type' => 'text/plain',
|
||||||
'tmp_name' => 'owfdskjasdfsa',
|
'tmp_name' => 'owfdskjasdfsa'.$suffix,
|
||||||
'error' => UPLOAD_ERR_OK,
|
'error' => UPLOAD_ERR_OK,
|
||||||
'size' => 100,
|
'size' => 100,
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user