Skip to content

Commit e814f0b

Browse files
committed
Fix JSON context extraction on Windows
Handle CRLF line endings when JSON contains control characters by replacing both \r\n and \r with escaped newlines during JSON parsing error recovery.
1 parent b5b6e2e commit e814f0b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Logs/LaravelLog.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ protected function extractContextsFromFullText(): void
108108
$json_data = json_decode(trim($json_string), true);
109109

110110
if (json_last_error() == JSON_ERROR_CTRL_CHAR) {
111-
// might need to escape new lines
112-
$json_data = json_decode(str_replace("\n", '\\n', $json_string), true);
111+
// might need to escape new lines and carriage returns
112+
$json_data = json_decode(str_replace(["\r\n", "\r", "\n"], ['\\n', '\\n', '\\n'], $json_string), true);
113113
}
114114

115115
if (json_last_error() == JSON_ERROR_NONE) {

0 commit comments

Comments
 (0)