mirror of
https://github.com/usebruno/bruno.git
synced 2025-08-18 22:16:24 +02:00
fix: boolean, undefined, null values eval in quickjs vm (#2893)
fix: boolean, undeifned, null values in pre-request vars
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
"@n8n/vm2": "^3.9.23"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node --experimental-vm-modules $(npx --no-install which jest) --testPathIgnorePatterns test.js",
|
||||
"test": "node --experimental-vm-modules $(npx which jest) --testPathIgnorePatterns test.js",
|
||||
"sandbox:bundle-libraries": "node ./src/sandbox/bundle-libraries.js"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@@ -21,11 +21,30 @@ const toNumber = (value) => {
|
||||
return Number.isInteger(num) ? parseInt(value, 10) : parseFloat(value);
|
||||
};
|
||||
|
||||
const removeQuotes = (str) => {
|
||||
if ((str.startsWith('"') && str.endsWith('"')) || (str.startsWith("'") && str.endsWith("'"))) {
|
||||
return str.slice(1, -1);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
const executeQuickJsVm = ({ script: externalScript, context: externalContext, scriptType = 'template-literal' }) => {
|
||||
if (!externalScript?.length || typeof externalScript !== 'string') {
|
||||
return externalScript;
|
||||
}
|
||||
externalScript = externalScript?.trim();
|
||||
|
||||
if (!isNaN(Number(externalScript))) {
|
||||
return Number(externalScript);
|
||||
}
|
||||
|
||||
if (externalScript === 'true') return true;
|
||||
if (externalScript === 'false') return false;
|
||||
if (externalScript === 'null') return null;
|
||||
if (externalScript === 'undefined') return undefined;
|
||||
|
||||
externalScript = removeQuotes(externalScript);
|
||||
|
||||
const vm = QuickJSSyncContext;
|
||||
|
||||
try {
|
||||
@@ -57,9 +76,22 @@ const executeQuickJsVm = ({ script: externalScript, context: externalContext, sc
|
||||
};
|
||||
|
||||
const executeQuickJsVmAsync = async ({ script: externalScript, context: externalContext, collectionPath }) => {
|
||||
if (!externalScript?.length || typeof externalScript !== 'string') {
|
||||
return externalScript;
|
||||
}
|
||||
externalScript = externalScript?.trim();
|
||||
|
||||
if (!isNaN(Number(externalScript))) {
|
||||
return toNumber(externalScript);
|
||||
}
|
||||
|
||||
if (externalScript === 'true') return true;
|
||||
if (externalScript === 'false') return false;
|
||||
if (externalScript === 'null') return null;
|
||||
if (externalScript === 'undefined') return undefined;
|
||||
|
||||
externalScript = removeQuotes(externalScript);
|
||||
|
||||
try {
|
||||
const module = await newQuickJSWASMModule();
|
||||
const vm = module.newContext();
|
||||
|
Reference in New Issue
Block a user