Permalink
Browse files

bug #30076 [Form] ignore _method forms in NativeRequestHandler (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Form] ignore _method forms in NativeRequestHandler

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #19017
| License       | MIT
| Doc PR        |

Commits
-------

bc4b091 ignore _method forms in NativeRequestHandler
  • Loading branch information...
nicolas-grekas committed Feb 8, 2019
2 parents a36dc51 + bc4b091 commit 68b4825d91f996f133a7338961f1aa2603c25795
@@ -115,6 +115,10 @@ public function handleRequest(FormInterface $form, $request = null)
return;
}
if (\is_array($data) && array_key_exists('_method', $data) && $method === $data['_method'] && !$form->has('_method')) {
unset($data['_method']);
}
$form->submit($data, 'PATCH' !== $method);
}
@@ -179,6 +179,59 @@ public function testMethodOverrideHeaderIgnoredIfNotPost()
$this->assertFalse($form->isSubmitted());
}
public function testFormIgnoresMethodFieldIfRequestMethodIsMatched()
{
$form = $this->createForm('foo', 'PUT', true);
$form->add($this->createForm('bar'));
$this->setRequestData('PUT', [
'foo' => [
'_method' => 'PUT',
'bar' => 'baz',
],
]);
$this->requestHandler->handleRequest($form, $this->request);
$this->assertSame([], $form->getExtraData());
}
public function testFormDoesNotIgnoreMethodFieldIfRequestMethodIsNotMatched()
{
$form = $this->createForm('foo', 'PUT', true);
$form->add($this->createForm('bar'));
$this->setRequestData('PUT', [
'foo' => [
'_method' => 'DELETE',
'bar' => 'baz',
],
]);
$this->requestHandler->handleRequest($form, $this->request);
$this->assertSame(['_method' => 'DELETE'], $form->getExtraData());
}
public function testMethodSubFormIsSubmitted()
{
$form = $this->createForm('foo', 'PUT', true);
$form->add($this->createForm('_method'));
$form->add($this->createForm('bar'));
$this->setRequestData('PUT', [
'foo' => [
'_method' => 'PUT',
'bar' => 'baz',
],
]);
$this->requestHandler->handleRequest($form, $this->request);
$this->assertTrue($form->get('_method')->isSubmitted());
$this->assertSame('PUT', $form->get('_method')->getData());
}
protected function setRequestData($method, $data, $files = [])
{
if ('GET' === $method) {

0 comments on commit 68b4825

Please sign in to comment.