Skip to content

Commit

Permalink
Merge pull request #407 from mrala/fix-json-parsing
Browse files Browse the repository at this point in the history
Fix escaping JSON issues
  • Loading branch information
Jean-Tinland authored Jul 2, 2024
2 parents 4c5ba7f + 44087f9 commit 99d4ef8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import * as Settings from "./settings";

export function parseJson(json) {
try {
return JSON.parse(json);
// clean up JSON that contains escape sequences,
// such as: `\\` or with `\"`
let cleanedJson = json
.replace(/\\/g, "\\\\")
.replace(/\\\"/g, '"');
return JSON.parse(cleanedJson);
} catch (error) {
// eslint-disable-next-line no-console
console.error(error, json);
Expand Down

0 comments on commit 99d4ef8

Please sign in to comment.