[Form] Fix UrlType transforms valid protocols

This commit is contained in:
Maxime STEINHAUSSER 2016-10-28 15:52:16 +02:00 committed by Fabien Potencier
parent 16b29a16de
commit 46dd3b9acb
2 changed files with 18 additions and 5 deletions

View File

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

View File

@ -40,15 +40,28 @@ class FixUrlProtocolListenerTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('http://www.symfony.com', $event->getData());
}
public function testSkipOtherProtocol()
public function provideUrlsWithSupportedProtocols()
{
return array(
array('ftp://www.symfony.com'),
array('chrome-extension://foo'),
array('h323://foo'),
array('iris.beep://foo'),
array('foo+bar://foo'),
);
}
/**
* @dataProvider provideUrlsWithSupportedProtocols
*/
public function testSkipOtherProtocol($url)
{
$data = 'ftp://www.symfony.com';
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
$event = new FormEvent($form, $data);
$event = new FormEvent($form, $url);
$filter = new FixUrlProtocolListener('http');
$filter->onSubmit($event);
$this->assertEquals('ftp://www.symfony.com', $event->getData());
$this->assertEquals($url, $event->getData());
}
}