Skip to content

Commit

Permalink
Fix decompiling of scriptlet parameters
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gorhill committed Jan 21, 2024
1 parent 12b9efe commit fa3a290
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/js/scriptlet-filtering-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')})`;
};
Expand Down

0 comments on commit fa3a290

Please sign in to comment.