From ec9af3a777c6aecdec2cefac0a8117fde5d13a78 Mon Sep 17 00:00:00 2001 From: Milos Stojanovic Date: Thu, 5 Sep 2019 15:50:25 +0200 Subject: [PATCH] File upload multibyte fix (PCRE_UTF8 flag) --- backend/Services/Tmpfs/Adapters/Tmpfs.php | 2 +- tests/backend/Feature/UploadTest.php | 39 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/backend/Services/Tmpfs/Adapters/Tmpfs.php b/backend/Services/Tmpfs/Adapters/Tmpfs.php index adceb0e..f7a2b27 100644 --- a/backend/Services/Tmpfs/Adapters/Tmpfs.php +++ b/backend/Services/Tmpfs/Adapters/Tmpfs.php @@ -131,7 +131,7 @@ class Tmpfs implements Service, TmpfsInterface [\x00-\x1F]| # control characters http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx [\x7F\xA0\xAD]| # non-printing characters DEL, NO-BREAK SPACE, SOFT HYPHEN [;\\\{}^\~`] # other non-safe - ~x', + ~xu', '-', (string) $filename ); diff --git a/tests/backend/Feature/UploadTest.php b/tests/backend/Feature/UploadTest.php index 6e88dc3..5682ed6 100644 --- a/tests/backend/Feature/UploadTest.php +++ b/tests/backend/Feature/UploadTest.php @@ -356,4 +356,43 @@ class UploadTest extends TestCase ], ]); } + + public function testFileUploadWithMultibyteName() + { + $this->signIn('john@example.com', 'john123'); + + $files = ['file' => new UploadedFile(TEST_FILE, 'ąčęėįšųū.txt', 'text/plain', null, true)]; + + $data = [ + 'resumableChunkNumber' => 1, + 'resumableChunkSize' => 1048576, + 'resumableCurrentChunkSize' => 0.5 * 1024 * 1024, + 'resumableTotalChunks' => 1, + 'resumableTotalSize' => 0.5 * 1024 * 1024, + 'resumableType' => 'text/plain', + 'resumableIdentifier' => 'CHUNKS-SIMPLE-TEST', + 'resumableFilename' => "断及服务层流.txt", + 'resumableRelativePath' => '/', + ]; + + $this->sendRequest('POST', '/upload', $data, $files); + + $this->assertOk(); + + $this->sendRequest('POST', '/getdir', [ + 'dir' => '/', + ]); + + $this->assertResponseJsonHas([ + 'data' => [ + 'files' => [ + 0 => [ + 'type' => 'file', + 'path' => '/断及服务层流.txt', + 'name' => '断及服务层流.txt', + ], + ], + ], + ]); + } }