Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6843a26

Browse filesBrowse files
committed
[Form] UrlType should not add protocol to emails
1 parent 93ed7c3 commit 6843a26
Copy full SHA for 6843a26

File tree

Expand file treeCollapse file tree

2 files changed

+13
-13
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-13
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/EventListener/FixUrlProtocolListener.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function onSubmit(FormEvent $event)
3636
{
3737
$data = $event->getData();
3838

39-
if ($this->defaultProtocol && $data && \is_string($data) && !preg_match('~^[\w+.-]+://~', $data)) {
39+
if ($this->defaultProtocol && $data && \is_string($data) && !preg_match('~^([\w+.-]+://|[^:/?@]++@)~', $data)) {
4040
$event->setData($this->defaultProtocol.'://'.$data);
4141
}
4242
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/EventListener/FixUrlProtocolListenerTest.php
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,38 @@
2020

2121
class FixUrlProtocolListenerTest extends TestCase
2222
{
23-
public function testFixHttpUrl()
23+
public function provideUrlToFix()
2424
{
25-
$data = 'www.symfony.com';
26-
$form = new Form(new FormConfigBuilder('name', null, new EventDispatcher()));
27-
$event = new FormEvent($form, $data);
28-
29-
$filter = new FixUrlProtocolListener('http');
30-
$filter->onSubmit($event);
31-
32-
$this->assertEquals('http://www.symfony.com', $event->getData());
25+
return [
26+
['www.symfony.com'],
27+
['twitter.com/@symfony'],
28+
];
3329
}
3430

35-
public function testSkipKnownUrl()
31+
/**
32+
* @dataProvider provideUrlToFix
33+
*/
34+
public function testFixHttpUrl($data)
3635
{
37-
$data = 'http://www.symfony.com';
3836
$form = new Form(new FormConfigBuilder('name', null, new EventDispatcher()));
3937
$event = new FormEvent($form, $data);
4038

4139
$filter = new FixUrlProtocolListener('http');
4240
$filter->onSubmit($event);
4341

44-
$this->assertEquals('http://www.symfony.com', $event->getData());
42+
$this->assertEquals('http://'.$data, $event->getData());
4543
}
4644

4745
public function provideUrlsWithSupportedProtocols()
4846
{
4947
return [
48+
['http://www.symfony.com'],
5049
['ftp://www.symfony.com'],
5150
['chrome-extension://foo'],
5251
['h323://foo'],
5352
['iris.beep://foo'],
5453
['foo+bar://foo'],
54+
['fabien@symfony.com'],
5555
];
5656
}
5757

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.