bug #26621 [Form] no type errors with invalid submitted data types (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form] no type errors with invalid submitted data types

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

Commits
-------

4217cc1348 no type errors with invalid submitted data types
This commit is contained in:
Fabien Potencier 2018-03-22 08:23:40 +01:00
commit 2349e977ff
2 changed files with 9 additions and 1 deletions

View File

@ -36,7 +36,7 @@ class FixUrlProtocolListener implements EventSubscriberInterface
{
$data = $event->getData();
if ($this->defaultProtocol && $data && !preg_match('~^[\w+.-]+://~', $data)) {
if ($this->defaultProtocol && $data && is_string($data) && !preg_match('~^[\w+.-]+://~', $data)) {
$event->setData($this->defaultProtocol.'://'.$data);
}
}

View File

@ -82,4 +82,12 @@ class UrlTypeTest extends TextTypeTest
'default_protocol' => array(),
));
}
public function testSubmitWithNonStringDataDoesNotBreakTheFixUrlProtocolListener()
{
$form = $this->factory->create(static::TESTED_TYPE);
$form->submit(array('domain.com', 'www.domain.com'));
$this->assertSame(array('domain.com', 'www.domain.com'), $form->getData());
}
}