diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php index 7c6e60278324d..e7037c483e775 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php @@ -142,8 +142,8 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) }; } - return function (FormInterface $form) { - return $form->getConfig()->getCompound() ? array() : ''; + return function (FormInterface $form, $defaultValue = '') { + return $form->getConfig()->getCompound() ? array() : $defaultValue; }; }; diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index f4696c0dfed34..505f854dc4764 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -1106,7 +1106,7 @@ private function viewToNorm($value) $transformers = $this->config->getViewTransformers(); if (!$transformers) { - return '' === $value ? null : $value; + return $value; } for ($i = count($transformers) - 1; $i >= 0; --$i) { diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php index 254b2a8e4e1b3..ab47be2a1780c 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php @@ -43,10 +43,22 @@ public function testSubmitAddsNoDefaultProtocolIfEmpty() $form->submit(''); - $this->assertNull($form->getData()); + $this->assertSame('',$form->getData()); // the data given was empty string so we should compare it to empty $this->assertSame('', $form->getViewData()); } + public function testSubmitAddsNoDefaultProtocolIfNull() + { + $form = $this->factory->create('url', null, array( + 'default_protocol' => 'http', + )); + + $form->submit(null); + + $this->assertNull($form->getData()); + $this->assertSame('', $form->getViewData()); + } + public function testSubmitAddsNoDefaultProtocolIfSetToNull() { $form = $this->factory->create('url', null, array(