Skip to content

Commit 0c15d5e

Browse files
Merge branch '6.4' into 7.2
* 6.4: Fix: prevent "Cannot traverse an already closed generator" error by materializing Traversable input [HttpFoundation] Fix: Encode path in X-Accel-Redirect header
2 parents c665ed9 + 6b7c97f commit 0c15d5e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

BinaryFileResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public function prepare(Request $request): static
237237
$path = $location.substr($path, \strlen($pathPrefix));
238238
// Only set X-Accel-Redirect header if a valid URI can be produced
239239
// as nginx does not serve arbitrary file paths.
240-
$this->headers->set($type, $path);
240+
$this->headers->set($type, rawurlencode($path));
241241
$this->maxlen = 0;
242242
break;
243243
}

Tests/BinaryFileResponseTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,15 @@ public function testXAccelMapping($realpath, $mapping, $virtual)
314314
$property->setValue($response, $file);
315315

316316
$response->prepare($request);
317-
$this->assertEquals($virtual, $response->headers->get('X-Accel-Redirect'));
317+
$header = $response->headers->get('X-Accel-Redirect');
318+
319+
if ($virtual) {
320+
// Making sure the path doesn't contain characters unsupported by nginx
321+
$this->assertMatchesRegularExpression('/^([^?%]|%[0-9A-F]{2})*$/', $header);
322+
$header = rawurldecode($header);
323+
}
324+
325+
$this->assertEquals($virtual, $header);
318326
}
319327

320328
public function testDeleteFileAfterSend()
@@ -361,6 +369,7 @@ public static function getSampleXAccelMappings()
361369
['/home/Foo/bar.txt', '/var/www/=/files/,/home/Foo/=/baz/', '/baz/bar.txt'],
362370
['/home/Foo/bar.txt', '"/var/www/"="/files/", "/home/Foo/"="/baz/"', '/baz/bar.txt'],
363371
['/tmp/bar.txt', '"/var/www/"="/files/", "/home/Foo/"="/baz/"', null],
372+
['/var/www/var/www/files/foo%.txt', '/var/www/=/files/', '/files/var/www/files/foo%.txt'],
364373
];
365374
}
366375

0 commit comments

Comments
 (0)