From e2257aa17b2b2566ab3bb8c4ec3e6388b24686d9 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Sun, 6 Mar 2016 11:04:27 +0000 Subject: [PATCH 1/2] [HttpFoundation] Fix the build on windows (with mbstring extension missing) --- .../Component/HttpFoundation/BinaryFileResponse.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index 490726dadf799..202eee578bfc2 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -161,17 +161,7 @@ public function setContentDisposition($disposition, $filename = '', $filenameFal } if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || false !== strpos($filename, '%'))) { - $encoding = mb_detect_encoding($filename, null, true); - - for ($i = 0; $i < mb_strlen($filename, $encoding); ++$i) { - $char = mb_substr($filename, $i, 1, $encoding); - - if ('%' === $char || ord($char) < 32 || ord($char) > 126) { - $filenameFallback .= '_'; - } else { - $filenameFallback .= $char; - } - } + $filenameFallback = preg_replace('/[^\x20-\x7e]|%/u', '_', $filename); } $dispositionHeader = $this->headers->makeDisposition($disposition, $filename, $filenameFallback); From 0b01fb1f1dbef6e7ef9e4a8c67169d30b78bb2e9 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Sun, 6 Mar 2016 17:14:59 +0000 Subject: [PATCH 2/2] [HttpFoundation] Fix the test on windows A file with non-ascii characters in the name needs to be created from PHP in order for it to be read properly on all platforms. --- .../HttpFoundation/Tests/BinaryFileResponseTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php index ac6c3288aebc3..cd5369811d5fe 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php @@ -36,7 +36,13 @@ public function testConstruction() public function testConstructWithNonAsciiFilename() { - new BinaryFileResponse(__DIR__.'/Fixtures/föö.html', 200, array(), true, 'attachment'); + touch(sys_get_temp_dir().'/fööö.html'); + + $response = new BinaryFileResponse(sys_get_temp_dir().'/fööö.html', 200, array(), true, 'attachment'); + + $this->assertSame('fööö.html', $response->getFile()->getFilename()); + + @unlink(sys_get_temp_dir().'/fööö.html'); } /**