From 9c5cd51a3bd597aca3651ab6d289469a55b23fb9 Mon Sep 17 00:00:00 2001 From: AlexRas007 Date: Tue, 5 Nov 2019 15:42:22 +0400 Subject: [PATCH] Fix #17632: Unicode file name was not correctly parsed in multipart forms --- framework/CHANGELOG.md | 1 + framework/web/MultipartFormDataParser.php | 2 +- .../web/MultipartFormDataParserTest.php | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 9986a10468..b2f5919369 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.30 under development ------------------------ +- Bug #17632: Unicode file name was not correctly parsed in multipart forms (AlexRas007, samdark) - Bug #17648: Handle empty column arrays in console `Table` widget (alex-code) - Bug #17657: Fix migration errors from missing `$schema` in RBAC init file when using MSSQL (PoohOka) diff --git a/framework/web/MultipartFormDataParser.php b/framework/web/MultipartFormDataParser.php index c9b7bd039a..13489c6567 100644 --- a/framework/web/MultipartFormDataParser.php +++ b/framework/web/MultipartFormDataParser.php @@ -217,7 +217,7 @@ class MultipartFormDataParser extends BaseObject implements RequestParserInterfa private function parseHeaders($headerContent) { $headers = []; - $headerParts = preg_split('/\\R/s', $headerContent, -1, PREG_SPLIT_NO_EMPTY); + $headerParts = preg_split('/\\R/su', $headerContent, -1, PREG_SPLIT_NO_EMPTY); foreach ($headerParts as $headerPart) { if (strpos($headerPart, ':') === false) { continue; diff --git a/tests/framework/web/MultipartFormDataParserTest.php b/tests/framework/web/MultipartFormDataParserTest.php index 3ab5482542..1212c72534 100644 --- a/tests/framework/web/MultipartFormDataParserTest.php +++ b/tests/framework/web/MultipartFormDataParserTest.php @@ -180,4 +180,21 @@ class MultipartFormDataParserTest extends TestCase $this->assertNotEmpty($_FILES['someFile']); $this->assertFalse(isset($_FILES['existingFile'])); } + + public function testParseUnicodeInFileName() + { + $unicodeName = 'х.jpg'; // this is Russian "х" + + $parser = new MultipartFormDataParser(); + + $boundary = '---------------------------703835582829016869506105'; + $contentType = 'multipart/form-data; boundary=' . $boundary; + $rawBody = "--{$boundary}\nContent-Disposition: form-data; name=\"someFile\"; filename=\"$unicodeName\";\nContent-Type: image/jpeg\r\n\r\nsome file content"; + $rawBody .= "\r\n--{$boundary}--"; + + $parser->parse($rawBody, $contentType); + + $this->assertNotEmpty($_FILES['someFile']); + $this->assertSame($unicodeName, $_FILES['someFile']['name']); + } }