From e5fba3cf83d9f1b91814846d67825b61a5b504e3 Mon Sep 17 00:00:00 2001 From: Flavian Sierk Date: Thu, 25 Jul 2013 11:50:20 +0200 Subject: [PATCH] [Form] fixes empty file-inputs get treated as extra field --- src/Symfony/Component/Form/Form.php | 2 +- .../Component/Form/Tests/CompoundFormTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index e1514847089e..43f46ca2286d 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -546,7 +546,7 @@ public function submit($submittedData, $clearMissing = true) foreach ($this->children as $name => $child) { $fieldValue = null; - if (isset($submittedData[$name])) { + if (array_key_exists($name, $submittedData)) { $fieldValue = $submittedData[$name]; unset($submittedData[$name]); } diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index 71c7b2a73479..34b11d39495d 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -13,6 +13,7 @@ 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 @@ public function testSubmitDoesNotSaveNullIfNotClearMissing() $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');