8000 bug #44939 [Form] UrlType should not add protocol to emails (GromNaN) · symfony/symfony@fa6a03a · GitHub
[go: up one dir, main page]

Skip to content

Commit fa6a03a

Browse files
bug #44939 [Form] UrlType should not add protocol to emails (GromNaN)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Form] UrlType should not add protocol to emails | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #43506 | License | MIT | Doc PR | n/a Replace #43707, since there is a bug in the `UrlType` auto-prepend behavior. The regex was suggested by `@nicolas`-grekas #43707 (comment) Commits ------- 4f99449 [Form] UrlType should not add protocol to emails
2 parents d922076 + 4f99449 commit fa6a03a

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
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
@@ -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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,49 @@
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+
['symfony.com?foo@bar'],
29+
['symfony.com#foo@bar'],
30+
['localhost'],
31+
];
3332
}
3433

35-
public function testSkipKnownUrl()
34+
/**
35+
* @dataProvider provideUrlToFix
36+
*/
37+
public function testFixUrl($data)
3638
{
37-
$data = 'http://www.symfony.com';
3839
$form = new Form(new FormConfigBuilder('name', null, new EventDispatcher()));
3940
$event = new FormEvent($form, $data);
4041

4142
$filter = new FixUrlProtocolListener('http');
4243
$filter->onSubmit($event);
4344

44-
$this->assertEquals('http://www.symfony.com', $event->getData());
45+
$this->assertEquals('http://'.$data, $event->getData());
4546
}
4647

47-
public function provideUrlsWithSupportedProtocols()
48+
public function provideUrlToSkip()
4849
{
4950
return [
51+
['http://www.symfony.com'],
5052
['ftp://www.symfony.com'],
53+
['https://twitter.com/@symfony'],
5154
['chrome-extension://foo'],
5255
['h323://foo'],
5356
['iris.beep://foo'],
5457
['foo+bar://foo'],
58+
['fabien@symfony.com'],
5559
];
5660
}
5761

5862
/**
59-
* @dataProvider provideUrlsWithSupportedProtocols
63+
* @dataProvider provideUrlToSkip
6064
*/
61-
public function testSkipOtherProtocol($url)
65+
public function testSkipUrl($url)
6266
{
6367
$form = new Form(new FormConfigBuilder('name', null, new EventDispatcher()));
6468
$event = new FormEvent($form, $url);

0 commit comments

Comments
 (0)
0