Skip to content

Commit

Permalink
Merge pull request #71 from foxycode/master
Browse files Browse the repository at this point in the history
Proper enconding of Content-Dispisition filename
  • Loading branch information
dg committed Mar 23, 2015
2 parents 45f4efb + da500c8 commit be8e35b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Application/Responses/FileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $htt
{
$httpResponse->setContentType($this->contentType);
$httpResponse->setHeader('Content-Disposition',
($this->forceDownload ? 'attachment' : 'inline') . '; filename="' . $this->name . '"');
($this->forceDownload ? 'attachment' : 'inline')
. '; filename="' . $this->name . '"'
. '; filename*=utf-8\'\'' . rawurlencode($this->name));

$filesize = $length = filesize($this->file);
$handle = fopen($this->file, 'r');
Expand Down
18 changes: 16 additions & 2 deletions tests/Application/FileResponse.contentDisposition.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test(function() {
$fileResponse->send(new Http\Request(new Http\UrlScript), $response = new Http\Response);

Assert::same( $origData, ob_get_clean() );
Assert::same( 'attachment; filename="' . $fileName . '"', $response->getHeader('Content-Disposition') );
Assert::same( 'attachment; filename="' . $fileName . '"; filename*=utf-8\'\'' . rawurlencode($fileName), $response->getHeader('Content-Disposition') );
});


Expand All @@ -44,5 +44,19 @@ test(function() {
$fileResponse->send(new Http\Request(new Http\UrlScript), $response = new Http\Response);

Assert::same( $origData, ob_get_clean() );
Assert::same('inline; filename="' . $fileName . '"', $response->getHeader('Content-Disposition'));
Assert::same('inline; filename="' . $fileName . '"; filename*=utf-8\'\'' . rawurlencode($fileName), $response->getHeader('Content-Disposition'));
});


test(function() {
$file = __FILE__;
$fileName = '啪lu钮ou膷k媒 k暖艌.txt';
$fileResponse = new FileResponse($file, $fileName);
$origData = file_get_contents($file);

ob_start();
$fileResponse->send(new Http\Request(new Http\UrlScript), $response = new Http\Response);

Assert::same( $origData, ob_get_clean() );
Assert::same('attachment; filename="' . $fileName . '"; filename*=utf-8\'\'' . rawurlencode($fileName), $response->getHeader('Content-Disposition'));
});

0 comments on commit be8e35b

Please sign in to comment.