Explorar el Código

[Form] ResizeFormListener::preBind() now handles empty strings. Fixes https://github.com/symfony/symfony/pull/40

Bernhard Schussek hace 14 años
padre
commit
9582221862

+ 1 - 1
src/Symfony/Component/Form/EventListener/ResizeFormListener.php

@@ -94,7 +94,7 @@ class ResizeFormListener implements EventSubscriberInterface
         $form = $event->getForm();
         $data = $event->getData();
 
-        if (null === $data) {
+        if (null === $data || '' === $data) {
             $data = array();
         }
 

+ 13 - 0
tests/Symfony/Tests/Component/Form/EventListener/ResizeFormListenerTest.php

@@ -183,6 +183,19 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
         $this->assertFalse($this->form->has('1'));
     }
 
+    // fixes https://github.com/symfony/symfony/pull/40
+    public function testPreBindDealsWithEmptyData()
+    {
+        $this->form->add($this->getForm('1'));
+
+        $data = '';
+        $event = new DataEvent($this->form, $data);
+        $listener = new ResizeFormListener($this->factory, 'text', true);
+        $listener->preBind($event);
+
+        $this->assertFalse($this->form->has('1'));
+    }
+
     public function testOnBindNormDataRemovesEntriesMissingInTheFormIfResizable()
     {
         $this->form->add($this->getForm('1'));