Skip to content

Commit 201f7ae

Browse files
Merge branch '5.4' into 6.0
* 5.4: (21 commits) [Finder] Fix finding VCS re-included files in excluded directory [Yaml] Improve the deprecation warnings for octal numbers to suggest migrating Fix Choice constraint with associative choices array [Form] UrlType should not add protocol to emails [Dotenv] Fix bootEnv() override with .env.local.php when the env key already exists Silence isatty warnings during tty detection [Serializer] Fix AbstractObjectNormalizer not considering pseudo type false [Notifier] Fix encoding of messages with FreeMobileTransport [Cache] workaround PHP crash [Console] Fix PHP 8.1 deprecation in ChoiceQuestion [HttpKernel] Fix compatibility with php bridge and already started php sessions [Notifier] smsapi-notifier - correct encoding Replaced full CoC text with link to documentation Making the parser stateless [Console] fix restoring stty mode on CTRL+C fix merge (bis) fix merge [Process] Avoid calling fclose on an already closed resource [GHA] test tty group [DI] Fix tests on PHP 7.1 ...
2 parents d01b802 + 2fa60c1 commit 201f7ae

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

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
}

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+
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)