Skip to content

Navigation Menu

Sign in
Appearance settings

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 9762238

Browse filesBrowse files
committed
[HttpFoundation] Throw exception if filename encoding cannot be detected
1 parent ee58cfc commit 9762238
Copy full SHA for 9762238

File tree

2 files changed

+15
-0
lines changed
Filter options

2 files changed

+15
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ public function setAutoEtag()
154154
* @param string $filenameFallback A fallback filename, containing only ASCII characters. Defaults to an automatically encoded filename
155155
*
156156
* @return $this
157+
*
158+
* @throws \InvalidArgumentException
157159
*/
158160
public function setContentDisposition($disposition, $filename = '', $filenameFallback = '')
159161
{
@@ -164,6 +166,10 @@ public function setContentDisposition($disposition, $filename = '', $filenameFal
164166
if ('' === $filenameFallback && (!preg_match('/^[\x20-\x7e]*$/', $filename) || false !== strpos($filename, '%'))) {
165167
$encoding = mb_detect_encoding($filename, null, true);
166168

169+
if (false === $encoding) {
170+
throw new \InvalidArgumentException('The filename encoding cannot be detected.');
171+
}
172+
167173
for ($i = 0, $filenameLength = mb_strlen($filename, $encoding); $i < $filenameLength; ++$i) {
168174
$char = mb_substr($filename, $i, 1, $encoding);
169175

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ public function testSetContentDispositionGeneratesSafeFallbackFilename()
6868
$this->assertSame('attachment; filename="f__.html"; filename*=utf-8\'\'f%C3%B6%C3%B6.html', $response->headers->get('Content-Disposition'));
6969
}
7070

71+
/**
72+
* @expectedException \InvalidArgumentException
73+
*/
74+
public function testSetContentDispositionThrowsExceptionWhenPassingInvalidEncodedFilename()
75+
{
76+
$response = new BinaryFileResponse(__FILE__);
77+
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, utf8_decode('föö.html'));
78+
}
79+
7180
/**
7281
* @dataProvider provideRanges
7382
*/

0 commit comments

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