Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

escape newlines in malformed JSON #241

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading