From fa3a290ad40e54e90dcc7268d02b93194080e990 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 20 Jan 2024 21:46:12 -0500 Subject: [PATCH] Fix decompiling of scriptlet parameters Scriptlets parameters which are quoted must be re-quoted when output to the logger to be sure they can be properly looked up in the list, and that they can be used through copy-paste operations. --- src/js/scriptlet-filtering-core.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/js/scriptlet-filtering-core.js b/src/js/scriptlet-filtering-core.js index 125eb87d5..e1f963d4b 100644 --- a/src/js/scriptlet-filtering-core.js +++ b/src/js/scriptlet-filtering-core.js @@ -99,7 +99,21 @@ const patchScriptlet = (content, arglist) => { }; const decompile = json => { - const args = JSON.parse(json).map(s => s.replace(/,/g, '\\,')); + const args = JSON.parse(json).map(s => { + if ( /^(["'`]).+\1$/.test(s) ) { + const c0 = s.charAt(0); + const inner = s.slice(1,-1); + if ( c0 === '"' || c0 === '`' ) { + return inner.includes("'") + ? '`' + s.replace(/`/g, '\\`') + '`' + : `'${s}'`; + } + return inner.includes('"') + ? '`' + s.replace(/`/g, '\\`') + '`' + : `"${s}"`; + } + return s.replace(/,/g, '\\,'); + }); if ( args.length === 0 ) { return '+js()'; } return `+js(${args.join(', ')})`; };