1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-11 07:34:12 +02:00

Let indexed arrays to support inline linebreaks in LineFormatter (#1818)

This commit is contained in:
dong
2023-10-27 07:31:42 -05:00
committed by GitHub
parent 5be54eaa1e
commit 8813064010
2 changed files with 3 additions and 1 deletions

View File

@@ -192,7 +192,7 @@ class LineFormatter extends NormalizerFormatter
protected function replaceNewlines(string $str): string
{
if ($this->allowInlineLineBreaks) {
if (0 === strpos($str, '{')) {
if (0 === strpos($str, '{') || 0 === strpos($str, '[')) {
$str = preg_replace('/(?<!\\\\)\\\\[rn]/', "\n", $str);
if (null === $str) {
$pcreErrorCode = preg_last_error();

View File

@@ -147,6 +147,8 @@ class LineFormatterTest extends TestCase
$formatter->allowInlineLineBreaks();
self::assertSame('{"test":"foo'."\n".'bar\\\\name-with-n"}', $formatter->stringify(["test" => "foo\nbar\\name-with-n"]));
self::assertSame('["indexed'."\n".'arrays'."\n".'without'."\n".'key","foo'."\n".'bar\\\\name-with-n"]', $formatter->stringify(["indexed\narrays\nwithout\nkey", "foo\nbar\\name-with-n"]));
self::assertSame('[{"first":"multi-dimensional'."\n".'arrays"},{"second":"foo'."\n".'bar\\\\name-with-n"}]', $formatter->stringify([["first" => "multi-dimensional\narrays"], ["second" => "foo\nbar\\name-with-n"]]));
}
public function testDefFormatWithExceptionAndStacktraceParserFull()