From 0cddb94e6d239b40320fe1121994eab12eeb56fa Mon Sep 17 00:00:00 2001 From: Ivan Paramonau Date: Mon, 15 Sep 2025 16:56:56 -0400 Subject: [PATCH] utils: Try to fix more JSON errors with JSON5 lib --- lib/utils.js | 7 +++++++ package.json | 1 + 2 files changed, 8 insertions(+) diff --git a/lib/utils.js b/lib/utils.js index 22b9476ef..e56c356f9 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -9,6 +9,7 @@ import { cache } from './cache.js'; import * as htmlUtils from './html-utils.js'; import log from '../logging.js'; import { resolve } from 'url'; +import JSON5 from 'json5'; import CONFIG from '../config.loader.js'; @@ -343,6 +344,12 @@ export function parseJSONSource(text, decode) { // default parser failed. Let's try to forgive } + try { + return JSON5.parse(decode ? entities.decodeHTML(decode(text)) : entities.decodeHTML(text)); + } catch (ex) { + // parser failed. Let's try to forgive more + } + var s = text; // replace opening ( and closing ) diff --git a/package.json b/package.json index 6997ea426..b3519962b 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "htmlparser2": "^7.2.0", "iconv-lite": "^0.6.3", "jslint": "^0.12.1", + "json5": "^2.2.3", "jsontoxml": "^1.0.1", "memcached": "2.2.2", "moment": "^2.30.1",