Skip to content

Commit

Permalink
Merge pull request #241 from opcodesio/escape-newlines-in-malformed-json
Browse files Browse the repository at this point in the history
escape newlines in malformed JSON
  • Loading branch information
arukompas authored Jul 10, 2023
2 parents 30a53d5 + f3dfab7 commit d3c6f66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opcodesio/log-viewer",
"version": "v2.5.0",
"version": "v2.5.1",
"description": "Fast and easy-to-use log viewer for your Laravel application",
"keywords": [
"arukompas",
Expand Down
6 changes: 6 additions & 0 deletions src/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public function extractContextsFromFullText(): void
foreach ($matches[0] as $json_string) {
// Try to decode the JSON string. If it fails, json_last_error() will return a non-zero value.
$json_data = json_decode($json_string, true);

if (json_last_error() == JSON_ERROR_CTRL_CHAR) {
// might need to escape new lines
$json_data = json_decode(str_replace("\n", "\\n", $json_string), true);
}

if (json_last_error() == JSON_ERROR_NONE) {
$this->contexts[] = $json_data;
$this->fullText = str_replace($json_string, '', $this->fullText);
Expand Down

0 comments on commit d3c6f66

Please sign in to comment.