8000 [Form] Fix UrlType transforms valid protocols · symfony/symfony@28f816a · GitHub
[go: up one dir, main page]

Skip to content

Commit 28f816a

Browse files
committed
[Form] Fix UrlType transforms valid protocols
1 parent d12f269 commit 28f816a

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/Symfony/Component/Form/Extension/Core/EventListener/FixUrlProtocolListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function onSubmit(FormEvent $event)
3838
{
3939
$data = $event->getData();
4040

41-
if ($this->defaultProtocol && $data && !preg_match('~^\w+://~', $data)) {
41+
if ($this->defaultProtocol && $data && strpos($data, '://') < 1) {
4242
$event->setData($this->defaultProtocol.'://'.$data);
4343
}
4444
}

src/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,28 @@ public function testSkipKnownUrl()
4040
$this->assertEquals('http://www.symfony.com', $event->getData());
4141
}
4242

43-
public function testSkipOtherProtocol()
43+
public function provideUrlsWithSupportedProtocols()
44+
{
45+
return array(
46+
array('ftp://www.symfony.com'),
47+
array('chrome-extension://foo'),
48+
array('h323://foo'),
49+
array('iris.beep://foo'),
50+
array('foo+bar://foo'),
51+
);
52+
}
53+
54+
/**
55+
* @dataProvider provideUrlsWithSupportedProtocols
56+
*/
57+
public function testSkipOtherProtocol($url)
4458
{
45-
$data = 'ftp://www.symfony.com';
4659
$form = $this->getMock('Symfony\Component\Form\Test\FormInterface');
47-
$event = new FormEvent($form, $data);
60+
$event = new FormEvent($form, $url);
4861

4962
$filter = new FixUrlProtocolListener('http');
5063
$filter->onSubmit($event);
5164

52-
$this->assertEquals('ftp://www.symfony.com', $event->getData());
65+
$this->assertEquals($url, $event->getData());
5366
}
5467
}

0 commit comments

Comments
 (0)
0