From 881306401018965b6f589fd4e05b38970582a75b Mon Sep 17 00:00:00 2001 From: dong Date: Fri, 27 Oct 2023 07:31:42 -0500 Subject: [PATCH] Let indexed arrays to support inline linebreaks in LineFormatter (#1818) --- src/Monolog/Formatter/LineFormatter.php | 2 +- tests/Monolog/Formatter/LineFormatterTest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Formatter/LineFormatter.php b/src/Monolog/Formatter/LineFormatter.php index 5d559923..eb838a7a 100644 --- a/src/Monolog/Formatter/LineFormatter.php +++ b/src/Monolog/Formatter/LineFormatter.php @@ -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('/(?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()