no type errors with invalid submitted data types

This commit is contained in:
Christian Flothmann 2018-03-21 18:01:56 +01:00
parent 25c2f91877
commit 4217cc1348
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());
}
}