[Form] Fix UrlType transforms valid protocols
This commit is contained in:
parent
16b29a16de
commit
46dd3b9acb
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user