From eb0ed5009be351a91b0ceb6d50c47f552818a564 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 25 Jun 2019 10:54:52 +0200 Subject: [PATCH 1/4] Test for Percent In Filename --- tests/Filesystem/FilesystemAdapterTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Filesystem/FilesystemAdapterTest.php b/tests/Filesystem/FilesystemAdapterTest.php index 7c111e9c29c7..a6b4997df96e 100644 --- a/tests/Filesystem/FilesystemAdapterTest.php +++ b/tests/Filesystem/FilesystemAdapterTest.php @@ -69,6 +69,15 @@ public function testDownloadNonAsciiEmptyFilename() $this->assertInstanceOf(StreamedResponse::class, $response); $this->assertEquals('attachment; filename=pizdyuk.txt; filename*=utf-8\'\'%D0%BF%D0%B8%D0%B7%D0%B4%D1%8E%D0%BA.txt', $response->headers->get('content-disposition')); } + + public function testDownloadPercentInFilename() + { + $this->filesystem->write('Hello%World.txt', 'Hello World'); + $files = new FilesystemAdapter($this->filesystem); + $response = $files->download('Hello%World.txt', 'Hello%World.txt'); + $this->assertInstanceOf(StreamedResponse::class, $response); + $this->assertEquals('attachment; filename=HelloWorld.txt; filename*=utf-8\'\'Hello%25World.txt', $response->headers->get('content-disposition')); + } public function testExists() { From 5ac66a8c341d659d61d128d52cc79f5a0de66219 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 25 Jun 2019 10:56:12 +0200 Subject: [PATCH 2/4] Convert percentage sign in fallback filename --- src/Illuminate/Filesystem/FilesystemAdapter.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Filesystem/FilesystemAdapter.php b/src/Illuminate/Filesystem/FilesystemAdapter.php index 6734ae18f6b4..667ca1e83be2 100644 --- a/src/Illuminate/Filesystem/FilesystemAdapter.php +++ b/src/Illuminate/Filesystem/FilesystemAdapter.php @@ -141,7 +141,7 @@ public function response($path, $name = null, array $headers = [], $disposition $filename = $name ?? basename($path); $disposition = $response->headers->makeDisposition( - $disposition, $filename, Str::ascii($filename) + $disposition, $filename, $this->fallbackName($filename) ); $response->headers->replace($headers + [ @@ -171,6 +171,17 @@ public function download($path, $name = null, array $headers = []) { return $this->response($path, $name, $headers, 'attachment'); } + + /** + * Convert the string to ASCII characters that are equivalent to the given name. + * + * @param string $name + * @return string + */ + protected function fallbackName($name) + { + return str_replace('%', '', Str::ascii($name)); + } /** * Write the contents of a file. From c9303aedc273a57cba589235247c63845a66c7dc Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 25 Jun 2019 11:00:38 +0200 Subject: [PATCH 3/4] CS --- src/Illuminate/Filesystem/FilesystemAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Filesystem/FilesystemAdapter.php b/src/Illuminate/Filesystem/FilesystemAdapter.php index 667ca1e83be2..9198c757da86 100644 --- a/src/Illuminate/Filesystem/FilesystemAdapter.php +++ b/src/Illuminate/Filesystem/FilesystemAdapter.php @@ -171,7 +171,7 @@ public function download($path, $name = null, array $headers = []) { return $this->response($path, $name, $headers, 'attachment'); } - + /** * Convert the string to ASCII characters that are equivalent to the given name. * From e80ff254924c7ccb601933213197de72369acfcb Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 25 Jun 2019 11:01:30 +0200 Subject: [PATCH 4/4] CS --- tests/Filesystem/FilesystemAdapterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Filesystem/FilesystemAdapterTest.php b/tests/Filesystem/FilesystemAdapterTest.php index a6b4997df96e..3be440b353a3 100644 --- a/tests/Filesystem/FilesystemAdapterTest.php +++ b/tests/Filesystem/FilesystemAdapterTest.php @@ -69,7 +69,7 @@ public function testDownloadNonAsciiEmptyFilename() $this->assertInstanceOf(StreamedResponse::class, $response); $this->assertEquals('attachment; filename=pizdyuk.txt; filename*=utf-8\'\'%D0%BF%D0%B8%D0%B7%D0%B4%D1%8E%D0%BA.txt', $response->headers->get('content-disposition')); } - + public function testDownloadPercentInFilename() { $this->filesystem->write('Hello%World.txt', 'Hello World');