[BUGFIX] Keep UTF-8 characters unescaped in JsonView 01/56501/3
authorOliver Klee <typo3-coding@oliverklee.de>
Sat, 31 Mar 2018 19:28:41 +0000 (21:28 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Thu, 5 Apr 2018 14:27:12 +0000 (16:27 +0200)
Resolves: #84572
Releases: master, 8.7
Change-Id: I7ace7322bdefcaeae5ffcc9021a5f13b4f5aeb1a
Reviewed-on: https://review.typo3.org/56501
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/extbase/Classes/Mvc/View/JsonView.php
typo3/sysext/extbase/Tests/Unit/Mvc/View/JsonViewTest.php

index 20fa7a5..1ffd40d 100644 (file)
@@ -229,7 +229,7 @@ class JsonView extends AbstractView
             }
         }
         $propertiesToRender = $this->renderArray();
-        return json_encode($propertiesToRender);
+        return json_encode($propertiesToRender, JSON_UNESCAPED_UNICODE);
     }
 
     /**
index 5ef1c6c..9d578d6 100644 (file)
@@ -326,6 +326,46 @@ class JsonViewTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
+    public function renderKeepsUtf8CharactersUnescaped(): void
+    {
+        $value = 'G├╝rkchen';
+        $this->view->assign('value', $value);
+
+        $actualResult = $this->view->render();
+
+        $expectedResult = '"' . $value . '"';
+        $this->assertSame($expectedResult, $actualResult);
+    }
+
+    /**
+     * @return string[][]
+     */
+    public function escapeCharacterDataProvider(): array
+    {
+        return [
+            'backslash' => ['\\'],
+            'double quote' => ['"'],
+        ];
+    }
+
+    /**
+     * @test
+     * @param string $character
+     * @dataProvider escapeCharacterDataProvider
+     */
+    public function renderEscapesEscapeCharacters(string $character): void
+    {
+        $this->view->assign('value', $character);
+
+        $actualResult = $this->view->render();
+
+        $expectedResult = '"\\' . $character . '"';
+        $this->assertSame($expectedResult, $actualResult);
+    }
+
+    /**
+     * @test
+     */
     public function renderReturnsNullIfNameOfAssignedVariableIsNotEqualToValue()
     {
         $value = 'Foo';