[Form] Fix "Array was modified outside object" in ResizeFormListener.

This commit is contained in:
Chekote 2014-03-10 10:10:33 -05:00 committed by Fabien Potencier
parent d4a78fec32
commit aa63faea06
2 changed files with 21 additions and 2 deletions

View File

@ -139,11 +139,17 @@ class ResizeFormListener implements EventSubscriberInterface
// The data mapper only adds, but does not remove items, so do this
// here
if ($this->allowDelete) {
$toDelete = array();
foreach ($data as $name => $child) {
if (!$form->has($name)) {
unset($data[$name]);
$toDelete[] = $name;
}
}
foreach ($toDelete as $name) {
unset($data[$name]);
}
}
$event->setData($data);

View File

@ -254,7 +254,20 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(), $event->getData());
}
public function testOnSubmitDealsWithIteratorAggregate()
public function testOnSubmitDealsWithObjectBackedIteratorAggregate()
{
$this->form->add($this->getForm('1'));
$data = new \ArrayObject(array(0 => 'first', 1 => 'second', 2 => 'third'));
$event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener('text', array(), false, true);
$listener->onSubmit($event);
$this->assertArrayNotHasKey(0, $event->getData());
$this->assertArrayNotHasKey(2, $event->getData());
}
public function testOnSubmitDealsWithArrayBackedIteratorAggregate()
{
$this->form->add($this->getForm('1'));