Skip to content

Commit 65dca5d

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 117f1f2 + a414c5d commit 65dca5d

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

BinaryFileResponse.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,12 @@ public function prepare(Request $request): static
217217
}
218218
if ('x-accel-redirect' === strtolower($type)) {
219219
// Do X-Accel-Mapping substitutions.
220-
// @link https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-redirect
221-
$parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping', ''), ',=');
220+
// @link https://github.com/rack/rack/blob/main/lib/rack/sendfile.rb
221+
// @link https://mattbrictson.com/blog/accelerated-rails-downloads
222+
if (!$request->headers->has('X-Accel-Mapping')) {
223+
throw new \LogicException('The "X-Accel-Mapping" header must be set when "X-Sendfile-Type" is set to "X-Accel-Redirect".');
224+
}
225+
$parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping'), ',=');
222226
foreach ($parts as $part) {
223227
[$pathPrefix, $location] = $part;
224228
if (str_starts_with($path, $pathPrefix)) {

Request.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,12 @@ public static function create(string $uri, string $method = 'GET', array $parame
348348
$server['PATH_INFO'] = '';
349349
$server['REQUEST_METHOD'] = strtoupper($method);
350350

351-
$components = parse_url($uri);
352-
if (false === $components) {
351+
if (false === ($components = parse_url($uri)) && '/' === ($uri[0] ?? '')) {
353352
trigger_deprecation('symfony/http-foundation', '6.3', 'Calling "%s()" with an invalid URI is deprecated.', __METHOD__);
354-
$components = [];
353+
$components = parse_url($uri.'#');
354+
unset($components['fragment']);
355355
}
356+
356357
if (isset($components['host'])) {
357358
$server['SERVER_NAME'] = $components['host'];
358359
$server['HTTP_HOST'] = $components['host'];

Tests/RequestTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ public function testCreate()
263263
// Fragment should not be included in the URI
264264
$request = Request::create('http://test.com/foo#bar');
265265
$this->assertEquals('http://test.com/foo', $request->getUri());
266+
267+
$request = Request::create('/foo:123');
268+
$this->assertEquals('http://localhost/foo:123', $request->getUri());
266269
}
267270

268271
public function testCreateWithRequestUri()

0 commit comments

Comments
 (0)