Skip to content

Commit d3c6f66

Browse files
authored
Merge pull request #241 from opcodesio/escape-newlines-in-malformed-json
escape newlines in malformed JSON
2 parents 30a53d5 + f3dfab7 commit d3c6f66

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opcodesio/log-viewer",
3-
"version": "v2.5.0",
3+
"version": "v2.5.1",
44
"description": "Fast and easy-to-use log viewer for your Laravel application",
55
"keywords": [
66
"arukompas",

src/Log.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ public function extractContextsFromFullText(): void
149149
foreach ($matches[0] as $json_string) {
150150
// Try to decode the JSON string. If it fails, json_last_error() will return a non-zero value.
151151
$json_data = json_decode($json_string, true);
152+
153+
if (json_last_error() == JSON_ERROR_CTRL_CHAR) {
154+
// might need to escape new lines
155+
$json_data = json_decode(str_replace("\n", "\\n", $json_string), true);
156+
}
157+
152158
if (json_last_error() == JSON_ERROR_NONE) {
153159
$this->contexts[] = $json_data;
154160
$this->fullText = str_replace($json_string, '', $this->fullText);

0 commit comments

Comments
 (0)