From fbaad2c2b7678441e2e484bf9b95231dc9c8e8b8 Mon Sep 17 00:00:00 2001 From: Omar Shaban Date: Fri, 2 Oct 2015 20:56:54 +0200 Subject: [PATCH 1/4] Bug #13291 [Form] Forward Form::submit(Request) to Form::HandleRequest When the argument of Form::submit is a Request object it forwards to Form::HandleRequest. Fixes the issue with uploaded files exceeding post_max_size, and form marked valid with empty fields. --- src/Symfony/Component/Form/Form.php | 5 +++++ .../Component/Form/Tests/SimpleFormTest.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 7a18dcb80078a..94b910aee6e8c 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -21,6 +21,7 @@ use Symfony\Component\Form\Util\InheritDataAwareIterator; use Symfony\Component\Form\Util\OrderedHashMap; use Symfony\Component\PropertyAccess\PropertyPath; +use Symfony\Component\HttpFoundation\Request; /** * Form represents a form. @@ -507,6 +508,10 @@ public function handleRequest($request = null) */ public function submit($submittedData, $clearMissing = true) { + if ($submittedData instanceof Request) { + return $this->handleRequest($submittedData); + } + if ($this->submitted) { throw new AlreadySubmittedException('A form can only be submitted once'); } diff --git a/src/Symfony/Component/Form/Tests/SimpleFormTest.php b/src/Symfony/Component/Form/Tests/SimpleFormTest.php index 76752b9bd235a..477fcb6c2fef5 100644 --- a/src/Symfony/Component/Form/Tests/SimpleFormTest.php +++ b/src/Symfony/Component/Form/Tests/SimpleFormTest.php @@ -909,6 +909,25 @@ public function testHandleRequestForwardsToRequestHandler() $this->assertSame($form, $form->handleRequest('REQUEST')); } + /** + * Shall be removed in 3.0 + */ + public function testSubmitForwardsToRequestHandlerUsingRequestArgument() + { + $handler = $this->getMock('Symfony\Component\Form\RequestHandlerInterface'); + + $form = $this->getBuilder() + ->setRequestHandler($handler) + ->getForm(); + + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); + + $handler->expects($this->once()) + ->method('handleRequest') + ->with($this->identicalTo($form), $request); + $this->assertSame($form, $form->submit($request)); + } + public function testFormInheritsParentData() { $child = $this->getBuilder('child') From ca0dc71974b43bc7398145e2404786ffe8905f80 Mon Sep 17 00:00:00 2001 From: Omar Shaban Date: Sat, 3 Oct 2015 15:00:30 +0200 Subject: [PATCH 2/4] CI validation fix for missing period --- src/Symfony/Component/Form/Tests/SimpleFormTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Tests/SimpleFormTest.php b/src/Symfony/Component/Form/Tests/SimpleFormTest.php index 477fcb6c2fef5..a6839dfc72b09 100644 --- a/src/Symfony/Component/Form/Tests/SimpleFormTest.php +++ b/src/Symfony/Component/Form/Tests/SimpleFormTest.php @@ -910,7 +910,7 @@ public function testHandleRequestForwardsToRequestHandler() } /** - * Shall be removed in 3.0 + * Shall be removed in 3.0. */ public function testSubmitForwardsToRequestHandlerUsingRequestArgument() { From 02992aaa9f097aef1fccab6b90e4680839b89de8 Mon Sep 17 00:00:00 2001 From: Omar Shaban Date: Sat, 3 Oct 2015 15:07:05 +0200 Subject: [PATCH 3/4] Bug #13291: Added Form::bind Test Case --- .../Component/Form/Tests/SimpleFormTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Symfony/Component/Form/Tests/SimpleFormTest.php b/src/Symfony/Component/Form/Tests/SimpleFormTest.php index a6839dfc72b09..bea0a67426437 100644 --- a/src/Symfony/Component/Form/Tests/SimpleFormTest.php +++ b/src/Symfony/Component/Form/Tests/SimpleFormTest.php @@ -928,6 +928,25 @@ public function testSubmitForwardsToRequestHandlerUsingRequestArgument() $this->assertSame($form, $form->submit($request)); } + /** + * Shall be removed in 3.0. + */ + public function testBindForwardsToRequestHandler() + { + $handler = $this->getMock('Symfony\Component\Form\RequestHandlerInterface'); + + $form = $this->getBuilder() + ->setRequestHandler($handler) + ->getForm(); + + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); + + $handler->expects($this->once()) + ->method('handleRequest') + ->with($this->identicalTo($form), $request); + $this->assertSame($form, $form->bind($request)); + } + public function testFormInheritsParentData() { $child = $this->getBuilder('child') From adb565528458c684e6149883f5a1aa297bbf620c Mon Sep 17 00:00:00 2001 From: Omar Shaban Date: Sat, 3 Oct 2015 17:00:45 +0200 Subject: [PATCH 4/4] Bug #13291: check Form::$submitted before handleRequest call --- src/Symfony/Component/Form/Form.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 94b910aee6e8c..2cad0cf2ad1b2 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -508,14 +508,14 @@ public function handleRequest($request = null) */ public function submit($submittedData, $clearMissing = true) { - if ($submittedData instanceof Request) { - return $this->handleRequest($submittedData); - } - if ($this->submitted) { throw new AlreadySubmittedException('A form can only be submitted once'); } + if ($submittedData instanceof Request) { + return $this->handleRequest($submittedData); + } + // Initialize errors in the very beginning so that we don't lose any // errors added during listeners $this->errors = array();