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); 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'); } /**