diff --git a/typo3/sysext/core/Classes/Log/Writer/FileWriter.php b/typo3/sysext/core/Classes/Log/Writer/FileWriter.php index c33a1b65c23d5d2ccae4b5d91407dc868c634d70..7790fa64dfa2e4fc480a8a42b9a1c4e150076dc5 100644 --- a/typo3/sysext/core/Classes/Log/Writer/FileWriter.php +++ b/typo3/sysext/core/Classes/Log/Writer/FileWriter.php @@ -154,7 +154,7 @@ class FileWriter extends AbstractWriter if (isset($recordData['exception']) && $recordData['exception'] instanceof \Exception) { $recordData['exception'] = (string)$recordData['exception']; } - $data = '- ' . json_encode($recordData); + $data = '- ' . json_encode($recordData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); } $message = sprintf( diff --git a/typo3/sysext/core/Tests/Unit/Log/Writer/FileWriterTest.php b/typo3/sysext/core/Tests/Unit/Log/Writer/FileWriterTest.php index 39dc715f5cb93278498cd45acbc029aa6c0ac7fa..997371ac3958870748c7f32a395c79f679c64fdb 100644 --- a/typo3/sysext/core/Tests/Unit/Log/Writer/FileWriterTest.php +++ b/typo3/sysext/core/Tests/Unit/Log/Writer/FileWriterTest.php @@ -152,6 +152,28 @@ class FileWriterTest extends UnitTestCase $this->assertEquals($expectedResult, $logFileContents); } + /** + * @test + */ + public function logsToFileWithUnescapedCharacters(): void + { + $this->setUpVfsStream(); + + $recordWithData = GeneralUtility::makeInstance( + LogRecord::class, + $this->getUniqueId('test.core.log.fileWriter.recordWithData.'), + \TYPO3\CMS\Core\Log\LogLevel::INFO, + 'test record with unicode and slash in data to encode', + ['foo' => ['bar' => 'I paid 0.00€ for open source projects/code']] + ); + + $expectedResult = '{"foo":{"bar":"I paid 0.00€ for open source projects/code"}}'; + + $this->createWriter('encoded-data')->writeLog($recordWithData); + $logFileContents = trim(file_get_contents($this->getDefaultFileName('encoded-data'))); + $this->assertContains($expectedResult, $logFileContents); + } + /** * @test * @param LogRecord $record Record Test Data