Skip to content

Commit

Permalink
Let indexed arrays to support inline linebreaks in LineFormatter (#1818)
Browse files Browse the repository at this point in the history
  • Loading branch information
lddtime authored Oct 27, 2023
1 parent 5be54ea commit 8813064
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Monolog/Formatter/LineFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected function convertToString($data): string
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();
Expand Down
2 changes: 2 additions & 0 deletions tests/Monolog/Formatter/LineFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public function testInlineLineBreaksRespectsEscapedBackslashes()
$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()
Expand Down

0 comments on commit 8813064

Please sign in to comment.