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.
This commit is contained in:
Raymond Hill 2024-01-20 21:46:12 -05:00
parent 12b9efe74b
commit fa3a290ad4
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 15 additions and 1 deletions

View File

@ -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(', ')})`;
};