From 9207e8a44f794011b7f30a3858825158c587205c Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sat, 31 Mar 2018 21:28:41 +0200 Subject: [PATCH] [BUGFIX] Keep UTF-8 characters unescaped in JsonView Resolves: #84572 Releases: master, 8.7 Change-Id: I7ace7322bdefcaeae5ffcc9021a5f13b4f5aeb1a Reviewed-on: https://review.typo3.org/56501 Tested-by: TYPO3com Reviewed-by: Daniel Goerz Tested-by: Daniel Goerz Reviewed-by: Georg Ringer Tested-by: Georg Ringer Reviewed-by: Stefan Neufeind Tested-by: Stefan Neufeind --- .../extbase/Classes/Mvc/View/JsonView.php | 2 +- .../Tests/Unit/Mvc/View/JsonViewTest.php | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/typo3/sysext/extbase/Classes/Mvc/View/JsonView.php b/typo3/sysext/extbase/Classes/Mvc/View/JsonView.php index 20fa7a52eb26..1ffd40de8512 100644 --- a/typo3/sysext/extbase/Classes/Mvc/View/JsonView.php +++ b/typo3/sysext/extbase/Classes/Mvc/View/JsonView.php @@ -229,7 +229,7 @@ class JsonView extends AbstractView } } $propertiesToRender = $this->renderArray(); - return json_encode($propertiesToRender); + return json_encode($propertiesToRender, JSON_UNESCAPED_UNICODE); } /** diff --git a/typo3/sysext/extbase/Tests/Unit/Mvc/View/JsonViewTest.php b/typo3/sysext/extbase/Tests/Unit/Mvc/View/JsonViewTest.php index 5ef1c6c858d7..9d578d6a4242 100644 --- a/typo3/sysext/extbase/Tests/Unit/Mvc/View/JsonViewTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Mvc/View/JsonViewTest.php @@ -323,6 +323,46 @@ class JsonViewTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase $this->assertEquals($expectedResult, $actualResult); } + /** + * @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 */ -- 2.20.1