Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db8e84d

Browse filesBrowse files
Merge branch '7.2' into 7.3
* 7.2: Fix: prevent "Cannot traverse an already closed generator" error by materializing Traversable input [HttpFoundation] Fix: Encode path in X-Accel-Redirect header
2 parents 47745f3 + 3720f4c commit db8e84d
Copy full SHA for db8e84d

File tree

4 files changed

+39
-2
lines changed
Filter options

4 files changed

+39
-2
lines changed

‎src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
+1-1
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
}

‎src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php
+10-1
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

‎src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Encoder/CsvEncoder.php
+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public function encode(mixed $data, string $format, array $context = []): string
7272
} elseif (!$data) {
7373
$data = [[]];
7474
} else {
75+
if ($data instanceof \Traversable) {
76+
// Generators can only be iterated once — convert to array to allow multiple traversals
77+
$data = iterator_to_array($data);
78+
}
7579
// Sequential arrays of arrays are considered as collections
7680
$i = 0;
7781
foreach ($data as $key => $value) {

‎src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Encoder/CsvEncoderTest.php
+24
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,30 @@ public function testEndOfLinePassedInConstructor()
708708
$this->assertSame("foo,bar\r\nhello,test\r\n", $encoder->encode($value, 'csv'));
709709
}
710710

711+
/** @dataProvider provideIterable */
712+
public function testIterable(mixed $data)
713+
{
714+
$this->assertEquals(<<<'CSV'
715+
foo,bar
716+
hello,"hey ho"
717+
hi,"let's go"
718+
719+
CSV, $this->encoder->encode($data, 'csv'));
720+
}
721+
722+
public static function provideIterable()
723+
{
724+
$data = [
725+
['foo' => 'hello', 'bar' => 'hey ho'],
726+
['foo' => 'hi', 'bar' => 'let\'s go'],
727+
];
728+
729+
yield 'array' => [$data];
730+
yield 'array iterator' => [new \ArrayIterator($data)];
731+
yield 'iterator aggregate' => [new \IteratorIterator(new \ArrayIterator($data))];
732+
yield 'generator' => [(fn (): \Generator => yield from $data)()];
733+
}
734+
711735
/**
712736
* @group legacy
713737
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.