8000 bug #42253 [Form] Do not fix URL protocol for relative URLs (bogkonst… · symfony/symfony@c569ef1 · GitHub
[go: up one dir, main page]

Skip to content

Commit c569ef1

Browse files
bug #42253 [Form] Do not fix URL protocol for relative URLs (bogkonstantin)
This PR was merged into the 4.4 branch. Discussion ---------- [Form] Do not fix URL protocol for relative URLs | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Tickets | Fix #42329 | Deprecations? | no | License | MIT Example when it doesn't work correctly: /relative/path The data will be changed to "http:///relative/path" (3 slashes) Commits ------- 415dc19 [Form] Do not fix URL protocol for relative URLs
2 parents 2119155 + 415dc19 commit c569ef1

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
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: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,25 @@
2020

2121
class FixUrlProtocolListenerTest extends TestCase
2222
{
23+
/**
24+
* @dataProvider provideUrlToFix
25+
*/
26+
public function testFixUrl($data)
27+
{
28+
$form = new Form(new FormConfigBuilder('name', null, new EventDispatcher()));
29+
$event = new FormEvent($form, $data);
30+
31+
$filter = new FixUrlProtocolListener('http');
32+
$filter->onSubmit($event);
33+
34+
$this->assertSame('http://'.$data, $event->getData());
35+
}
36+
2337
public function provideUrlToFix()
2438
{
2539
return [
2640
['www.symfony.com'],
41+
['symfony.com/doc'],
2742
['twitter.com/@symfony'],
2843
['symfony.com?foo@bar'],
2944
['symfony.com#foo@bar'],
@@ -32,17 +47,17 @@ public function provideUrlToFix()
3247
}
3348

3449
/**
35-
* @dataProvider provideUrlToFix
50+
* @dataProvider provideUrlToSkip
3651
*/
37-
public function testFixUrl($data)
52+
public function testSkipUrl($url)
3853
{
3954
$form = new Form(new FormConfigBuilder('name', null, new EventDispatcher()));
40-
$event = new FormEvent($form, $data);
55+
$event = new FormEvent($form, $url);
4156

4257
$filter = new FixUrlProtocolListener('http');
4358
$filter->onSubmit($event);
4459

45-
$this->assertEquals('http://'.$data, $event->getData());
60+
$this->assertSame($url, $event->getData());
4661
}
4762

4863
public function provideUrlToSkip()
@@ -56,20 +71,9 @@ public function provideUrlToSkip()
5671
['iris.beep://foo'],
5772
['foo+bar://foo'],
5873
['fabien@symfony.com'],
74+
['//relative/url'],
75+
['/relative/url'],
76+
['./relative/url'],
5977
];
6078
}
61-
62-
/**
63-
* @dataProvider provideUrlToSkip
64-
*/
65-
public function testSkipUrl($url)
66-
{
67-
$form = new Form(new FormConfigBuilder('name', null, new EventDispatcher()));
68-
$event = new FormEvent($form, $url);
69-
70-
$filter = new FixUrlProtocolListener('http');
71-
$filter->onSubmit($event);
72-
73-
$this->assertEquals($url, $event->getData());
74-
}
7579
}

0 commit comments

Comments
 (0)
0