1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-24 10:06:08 +02:00

Fix replaceNewlines method to avoid replacing escaped backslashes, closes #1721, fixes #1720

This commit is contained in:
Pavel Bychko
2022-06-26 12:34:03 +03:00
committed by Jordi Boggiano
parent cf0f4b3814
commit 320909a1d1
2 changed files with 13 additions and 1 deletions

View File

@@ -186,7 +186,11 @@ class LineFormatter extends NormalizerFormatter
{
if ($this->allowInlineLineBreaks) {
if (0 === strpos($str, '{')) {
return str_replace(array('\r', '\n'), array("\r", "\n"), $str);
$str = preg_replace('/(?<!\\\\)\\\\[rn]/', "\n", $str);
if (null === $str) {
$pcreErrorCode = preg_last_error();
throw new \RuntimeException('Failed to run preg_replace: ' . $pcreErrorCode . ' / ' . Utils::pcreLastErrorMessage($pcreErrorCode));
}
}
return $str;