From 5952b0a31b6aac0718bc23aefe43560b9bfe8cc5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 3 Mar 2015 03:27:42 -0800 Subject: [PATCH] Stop mangling filenames when downloading them Summary: Fixes T6990. We unnecessarily mangle filenames when downloading them. Test Plan: - Reviewed "quoted-string" grammar in HTTP spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html) - Downloaded some non-latin binaries. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6990 Differential Revision: https://secure.phabricator.com/D11940 --- src/aphront/response/AphrontFileResponse.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aphront/response/AphrontFileResponse.php b/src/aphront/response/AphrontFileResponse.php index a5a7e90aa1..9e5bc50b48 100644 --- a/src/aphront/response/AphrontFileResponse.php +++ b/src/aphront/response/AphrontFileResponse.php @@ -15,9 +15,8 @@ final class AphrontFileResponse extends AphrontResponse { } public function setDownload($download) { - $download = preg_replace('/[^A-Za-z0-9_.-]/', '_', $download); if (!strlen($download)) { - $download = 'untitled_document.txt'; + $download = 'untitled'; } $this->download = $download; return $this; @@ -73,9 +72,10 @@ final class AphrontFileResponse extends AphrontResponse { $headers[] = array('X-Download-Options', 'noopen'); $filename = $this->getDownload(); + $filename = addcslashes($filename, '"\\'); $headers[] = array( 'Content-Disposition', - 'attachment; filename='.$filename, + 'attachment; filename="'.$filename.'"', ); }