merged branch Flask/ticket_8548 (PR #8575)
This PR was squashed before being merged into the 2.3 branch (closes #8575).
Discussion
----------
[Form] fixes empty file-inputs get treated as extra field
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #8548, #8566
| License | MIT
Commits
-------
e5fba3c
[Form] fixes empty file-inputs get treated as extra field
This commit is contained in:
commit
de1915f405
|
@ -546,7 +546,7 @@ class Form implements \IteratorAggregate, FormInterface
|
|||
|
||||
foreach ($this->children as $name => $child) {
|
||||
$fieldValue = null;
|
||||
if (isset($submittedData[$name])) {
|
||||
if (array_key_exists($name, $submittedData)) {
|
||||
$fieldValue = $submittedData[$name];
|
||||
unset($submittedData[$name]);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Tests;
|
|||
|
||||
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
|
||||
use Symfony\Component\Form\FormError;
|
||||
use Symfony\Component\Form\Forms;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Symfony\Component\Form\Tests\Fixtures\FixedDataTransformer;
|
||||
|
@ -73,6 +74,19 @@ class CompoundFormTest extends AbstractFormTest
|
|||
$this->form->submit(array(), false);
|
||||
}
|
||||
|
||||
public function testSubmitDoesNotAddExtraFieldForNullValues()
|
||||
{
|
||||
$factory = Forms::createFormFactoryBuilder()
|
||||
->getFormFactory();
|
||||
|
||||
$child = $factory->create('file', null, array('auto_initialize' => false));
|
||||
|
||||
$this->form->add($child);
|
||||
$this->form->submit(array('file' => null));
|
||||
|
||||
$this->assertCount(0, $this->form->getExtraData());
|
||||
}
|
||||
|
||||
public function testClearMissingFlagIsForwarded()
|
||||
{
|
||||
$child = $this->getMockForm('firstName');
|
||||
|
|
Reference in New Issue