Skip to content

Commit d48df3d

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: [Intl] Update ICU data from 74.1 to 75.1 use DeprecatedCallableInfo for Twig callables if possible [Filesystem] Add a warning about `chown()` and `chgrp()` on Windows [String] Update wcswidth data with Unicode 16 Work around parse_url() bug [Ldap] Clean `ldap_connect()` call in `LdapTestCase` [HttpFoundation] Update links for X-Accel-Redirect and fail properly when X-Accel-Mapping is missing
2 parents 6cbdb0c + 8bd84c5 commit d48df3d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Controller/RedirectController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,17 @@ public function urlRedirectAction(Request $request, string $path, bool $permanen
119119
$statusCode = $permanent ? 301 : 302;
120120
}
121121

122+
$scheme ??= $request->getScheme();
123+
124+
if (str_starts_with($path, '//')) {
125+
$path = $scheme.':'.$path;
126+
}
127+
122128
// redirect if the path is a full URL
123129
if (parse_url($path, \PHP_URL_SCHEME)) {
124130
return new RedirectResponse($path, $statusCode);
125131
}
126132

127-
$scheme ??= $request->getScheme();
128-
129133
if ($qs = $request->server->get('QUERY_STRING') ?: $request->getQueryString()) {
130134
if (!str_contains($path, '?')) {
131135
$qs = '?'.$qs;

Tests/Controller/RedirectControllerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,20 @@ public function testFullURLWithMethodKeep()
183183
$this->assertEquals(307, $returnResponse->getStatusCode());
184184
}
185185

186+
public function testProtocolRelative()
187+
{
188+
$request = new Request();
189+
$controller = new RedirectController();
190+
191+
$returnResponse = $controller->urlRedirectAction($request, '//foo.bar/');
192+
$this->assertRedirectUrl($returnResponse, 'http://foo.bar/');
193+
$this->assertSame(302, $returnResponse->getStatusCode());
194+
195+
$returnResponse = $controller->urlRedirectAction($request, '//foo.bar/', false, 'https');
196+
$this->assertRedirectUrl($returnResponse, 'https://foo.bar/');
197+
$this->assertSame(302, $returnResponse->getStatusCode());
198+
}
199+
186200
public function testUrlRedirectDefaultPorts()
187201
{
188202
$host = 'www.example.com';

0 commit comments

Comments
 (0)