From 5cfc1d0508cd57a1c2df95277fc2b1cecf8b5d0a Mon Sep 17 00:00:00 2001 From: Kyle Simpson Date: Tue, 21 Dec 2021 17:31:45 -0800 Subject: [PATCH] per #64, more fixes to address significant performance concerns --- minify.json.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/minify.json.js b/minify.json.js index 34889ce..4b6d6ad 100644 --- a/minify.json.js +++ b/minify.json.js @@ -1,5 +1,5 @@ /*! JSON.minify() - v0.2 (c) Kyle Simpson + v3.0.0 (c) Kyle Simpson MIT License */ @@ -26,7 +26,7 @@ if (!in_multiline_comment && !in_singleline_comment) { tmp2 = lc.substring(from); if (!in_string) { - tmp2 = tmp2.replace(/(\n|\r|\s)*/g,""); + tmp2 = tmp2.replace(/(\n|\r|\s)+/g,""); } new_str[ns++] = tmp2; } @@ -37,14 +37,12 @@ // a comment? check for previous `\` escaping immediately // leftward adjacent to this match if (tmp[0] == "\"" && !in_multiline_comment && !in_singleline_comment) { + // perform look-behind escaping match, but // limit left-context matching to only go back // to the position of the last token match // // see: https://github.com/getify/JSON.minify/issues/64 - lc.lastIndex = prevFrom; - - // perform leftward adjacent escaping match - tmp2 = lc.match(/(\\)*$/); + tmp2 = lc.substring(prevFrom).match(/\\+$/); // start of string with ", or unescaped " character found to end string? if (!in_string || !tmp2 || (tmp2[0].length % 2) == 0) {