Loading core/lib/Drupal/Component/Utility/Unicode.php +3 −3 Original line number Diff line number Diff line Loading @@ -537,16 +537,16 @@ public static function mimeHeaderEncode($string, $shorten = FALSE) { */ public static function mimeHeaderDecode($header) { $callback = function ($matches) { $data = ($matches[2] == 'B') ? base64_decode($matches[3]) : str_replace('_', ' ', quoted_printable_decode($matches[3])); $data = (strtolower($matches[2]) == 'b') ? base64_decode($matches[3]) : str_replace('_', ' ', quoted_printable_decode($matches[3])); if (strtolower($matches[1]) != 'utf-8') { $data = static::convertToUtf8($data, $matches[1]); } return $data; }; // First step: encoded chunks followed by other encoded chunks (need to collapse whitespace) $header = preg_replace_callback('/=\?([^?]+)\?(Q|B)\?([^?]+|\?(?!=))\?=\s+(?==\?)/', $callback, $header); $header = preg_replace_callback('/=\?([^?]+)\?([Qq]|[Bb])\?([^?]+|\?(?!=))\?=\s+(?==\?)/', $callback, $header); // Second step: remaining chunks (do not collapse whitespace) return preg_replace_callback('/=\?([^?]+)\?(Q|B)\?([^?]+|\?(?!=))\?=/', $callback, $header); return preg_replace_callback('/=\?([^?]+)\?([Qq]|[Bb])\?([^?]+|\?(?!=))\?=/', $callback, $header); } /** Loading core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php +45 −7 Original line number Diff line number Diff line Loading @@ -23,15 +23,13 @@ public function testSetStatus() { } /** * Tests multibyte encoding and decoding. * Tests multibyte encoding. * * @dataProvider providerTestMimeHeader * @covers ::mimeHeaderEncode * @covers ::mimeHeaderDecode */ public function testMimeHeader($value, $encoded) { public function testMimeHeaderEncode($value, $encoded) { $this->assertEquals($encoded, Unicode::mimeHeaderEncode($value)); $this->assertEquals($value, Unicode::mimeHeaderDecode($encoded)); } /** Loading @@ -44,9 +42,49 @@ public function testMimeHeader($value, $encoded) { */ public function providerTestMimeHeader() { return [ ['tést.txt', '=?UTF-8?B?dMOpc3QudHh0?='], // Simple ASCII characters. ['ASCII', 'ASCII'], "Base64 encoding" => ['tést.txt', '=?UTF-8?B?dMOpc3QudHh0?='], "ASCII characters only" => ['test.txt', 'test.txt'], ]; } /** * Tests multibyte decoding. * * @dataProvider providerTestMimeHeaderDecode * @covers ::mimeHeaderDecode */ public function testMimeHeaderDecode($value, $encoded) { $this->assertEquals($value, Unicode::mimeHeaderDecode($encoded)); } /** * Data provider for testMimeHeaderDecode(). * * @return array * An array containing a string and its encoded value. */ public function providerTestMimeHeaderDecode() { return [ 'Uppercase base64 encoding' => [ 'tést.txt', '=?utf-8?B?dMOpc3QudHh0?=', ], 'Uppercase quoted-printable encoding' => [ 'tést.txt', '=?UTF-8?Q?t=C3=A9st.txt?=', ], 'Lowercase base64 encoding' => [ 'tést.txt', '=?utf-8?b?dMOpc3QudHh0?=', ], 'Lowercase quoted-printable encoding' => [ 'tést.txt', '=?UTF-8?q?t=C3=A9st.txt?=', ], 'ASCII characters only' => [ 'test.txt', 'test.txt', ], ]; } Loading Loading
core/lib/Drupal/Component/Utility/Unicode.php +3 −3 Original line number Diff line number Diff line Loading @@ -537,16 +537,16 @@ public static function mimeHeaderEncode($string, $shorten = FALSE) { */ public static function mimeHeaderDecode($header) { $callback = function ($matches) { $data = ($matches[2] == 'B') ? base64_decode($matches[3]) : str_replace('_', ' ', quoted_printable_decode($matches[3])); $data = (strtolower($matches[2]) == 'b') ? base64_decode($matches[3]) : str_replace('_', ' ', quoted_printable_decode($matches[3])); if (strtolower($matches[1]) != 'utf-8') { $data = static::convertToUtf8($data, $matches[1]); } return $data; }; // First step: encoded chunks followed by other encoded chunks (need to collapse whitespace) $header = preg_replace_callback('/=\?([^?]+)\?(Q|B)\?([^?]+|\?(?!=))\?=\s+(?==\?)/', $callback, $header); $header = preg_replace_callback('/=\?([^?]+)\?([Qq]|[Bb])\?([^?]+|\?(?!=))\?=\s+(?==\?)/', $callback, $header); // Second step: remaining chunks (do not collapse whitespace) return preg_replace_callback('/=\?([^?]+)\?(Q|B)\?([^?]+|\?(?!=))\?=/', $callback, $header); return preg_replace_callback('/=\?([^?]+)\?([Qq]|[Bb])\?([^?]+|\?(?!=))\?=/', $callback, $header); } /** Loading
core/tests/Drupal/Tests/Component/Utility/UnicodeTest.php +45 −7 Original line number Diff line number Diff line Loading @@ -23,15 +23,13 @@ public function testSetStatus() { } /** * Tests multibyte encoding and decoding. * Tests multibyte encoding. * * @dataProvider providerTestMimeHeader * @covers ::mimeHeaderEncode * @covers ::mimeHeaderDecode */ public function testMimeHeader($value, $encoded) { public function testMimeHeaderEncode($value, $encoded) { $this->assertEquals($encoded, Unicode::mimeHeaderEncode($value)); $this->assertEquals($value, Unicode::mimeHeaderDecode($encoded)); } /** Loading @@ -44,9 +42,49 @@ public function testMimeHeader($value, $encoded) { */ public function providerTestMimeHeader() { return [ ['tést.txt', '=?UTF-8?B?dMOpc3QudHh0?='], // Simple ASCII characters. ['ASCII', 'ASCII'], "Base64 encoding" => ['tést.txt', '=?UTF-8?B?dMOpc3QudHh0?='], "ASCII characters only" => ['test.txt', 'test.txt'], ]; } /** * Tests multibyte decoding. * * @dataProvider providerTestMimeHeaderDecode * @covers ::mimeHeaderDecode */ public function testMimeHeaderDecode($value, $encoded) { $this->assertEquals($value, Unicode::mimeHeaderDecode($encoded)); } /** * Data provider for testMimeHeaderDecode(). * * @return array * An array containing a string and its encoded value. */ public function providerTestMimeHeaderDecode() { return [ 'Uppercase base64 encoding' => [ 'tést.txt', '=?utf-8?B?dMOpc3QudHh0?=', ], 'Uppercase quoted-printable encoding' => [ 'tést.txt', '=?UTF-8?Q?t=C3=A9st.txt?=', ], 'Lowercase base64 encoding' => [ 'tést.txt', '=?utf-8?b?dMOpc3QudHh0?=', ], 'Lowercase quoted-printable encoding' => [ 'tést.txt', '=?UTF-8?q?t=C3=A9st.txt?=', ], 'ASCII characters only' => [ 'test.txt', 'test.txt', ], ]; } Loading