Skip to content

Commit 0c93dc1

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: fix merge [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 PhpSubprocess: Add flag PREG_OFFSET_CAPTURE to preg_match to identify the offset 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 e967c07 + d48df3d commit 0c93dc1

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
@@ -115,13 +115,17 @@ public function urlRedirectAction(Request $request, string $path, bool $permanen
115115
$statusCode = $permanent ? 301 : 302;
116116
}
117117

118+
$scheme ??= $request->getScheme();
119+
120+
if (str_starts_with($path, '//')) {
121+
$path = $scheme.':'.$path;
122+
}
123+
118124
// redirect if the path is a full URL
119125
if (parse_url($path, \PHP_URL_SCHEME)) {
120126
return new RedirectResponse($path, $statusCode);
121127
}
122128

123-
$scheme ??= $request->getScheme();
124-
125129
if ($qs = $request->server->get('QUERY_STRING') ?: $request->getQueryString()) {
126130
if (!str_contains($path, '?')) {
127131
$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)