8000 [Form] NativeRequestHandler file handling fix · symfony/symfony@9b3421f · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b3421f

Browse files
mpajunenfabpot
authored andcommitted
[Form] NativeRequestHandler file handling fix
1 parent c0dcbed commit 9b3421f

File tree

6 files changed

+52
-8
lines changed

6 files changed

+52
-8
lines changed

src/Symfony/Component/Form/NativeRequestHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public function handleRequest(FormInterface $form, $request = null)
9898
}
9999

100100
$fixedFiles = array();
101-
foreach ($_FILES as $name => $file) {
102-
$fixedFiles[$name] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
101+
foreach ($_FILES as $fileKey => $file) {
102+
$fixedFiles[$fileKey] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
103103
}
104104

105105
if ('' === $name) {

src/Symfony/Component/Form/Tests/AbstractRequestHandlerTest.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,50 @@ public function testSubmitFileIfNoParam($method)
266266
$this->requestHandler->handleRequest($form, $this->request);
267267
}
268268

269+
/**
270+
* @dataProvider methodExceptGetProvider
271+
*/
272+
public function testSubmitMultipleFiles($method)
273+
{
274+
$form = $this->getMockForm('param1', $method);
275+
$file = $this->getMockFile();
276+
277+
$this->setRequestData($method, array(
278+
'param1' => null,
279+
), array(
280+
'param2' => $this->getMockFile('2'),
281+
'param1' => $file,
282+
'param3' => $this->getMockFile('3'),
283+
));
284+
285+
$form->expects($this->once())
286+
->method('submit')
287+
->with($file, 'PATCH' !== $method);
288+
289+
$this->requestHandler->handleRequest($form, $this->request);
290+
}
291+
292+
/**
293+
* @dataProvider methodExceptGetProvider
294+
*/
295+
public function testSubmitFileWithNamelessForm($method)
296+
{
297+
$form = $this->getMockForm(null, $method);
298+
$file = $this->getMockFile();
299+
300+
$this->setRequestData($method, array(
301+
'' => null,
302+
), array(
303+
'' => $file,
304+
));
305+
306+
$form->expects($this->once())
307+
->method('submit')
308+
->with($file, 'PATCH' !== $method);
309+
310+
$this->requestHandler->handleRequest($form, $this->request);
311+
}
312+
269313
/**
270314
* @dataProvider getPostMaxSizeFixtures
271315
*/
@@ -314,7 +358,7 @@ abstract protected function setRequestData($method, $data, $files = array());
314358

315359
abstract protected function getRequestHandler();
316360

317-
abstract protected function getMockFile();
361+
abstract protected function getMockFile($suffix = '');
318362

319363
protected function getMockForm($name, $method = null, $compound = true)
320364
{

src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ protected function getRequestHandler()
4646
return new HttpFoundationRequestHandler($this->serverParams);
4747
}
4848

49-
protected function getMockFile()
49+
protected function getMockFile($suffix = '')
5050
{
51-
return new UploadedFile(__DIR__.'/../../Fixtures/foo', 'foo');
51+
return new UploadedFile(__DIR__.'/../../Fixtures/foo'.$suffix, 'foo'.$suffix);
5252
}
5353
}

src/Symfony/Component/Form/Tests/Fixtures/foo2

Whitespace-only changes.

src/Symfony/Component/Form/Tests/Fixtures/foo3

Whitespace-only changes.

src/Symfony/Component/Form/Tests/NativeRequestHandlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ protected function getRequestHandler()
206206
return new NativeRequestHandler($this->serverParams);
207207
}
208208

209-
protected function getMockFile()
209+
protected function getMockFile($suffix = '')
210210
{
211211
return array(
212-
'name' => 'upload.txt',
212+
'name' => 'upload'.$suffix.'.txt',
213213
'type' => 'text/plain',
214-
'tmp_name' => 'owfdskjasdfsa',
214+
'tmp_name' => 'owfdskjasdfsa'.$suffix,
215215
'error' => UPLOAD_ERR_OK,
216216
'size' => 100,
217217
);

0 commit comments

Comments
 (0)
0