Skip to content

Commit

Permalink
Merge pull request #3805 from Pragadesh-45/fix/handle-assert-results
Browse files Browse the repository at this point in the history
Refactor: Improve expression handling across different runtimes (Fix: #3758)
  • Loading branch information
lohit-bruno authored Jan 15, 2025
2 parents 00c5298 + dbf1cad commit 6abd063
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
18 changes: 10 additions & 8 deletions packages/bruno-js/src/sandbox/quickjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ 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 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') {
Expand All @@ -44,7 +44,8 @@ const executeQuickJsVm = ({ script: externalScript, context: externalContext, sc
if (externalScript === 'null') return null;
if (externalScript === 'undefined') return undefined;

externalScript = removeQuotes(externalScript);
// This is commented out as part of the fix for #3758
// externalScript = removeQuotes(externalScript);

const vm = QuickJSSyncContext;

Expand Down Expand Up @@ -94,7 +95,8 @@ const executeQuickJsVmAsync = async ({ script: externalScript, context: external
if (externalScript === 'null') return null;
if (externalScript === 'undefined') return undefined;

externalScript = removeQuotes(externalScript);
// This is commented out as part of the fix for #3758
// externalScript = removeQuotes(externalScript);

try {
const module = await newQuickJSWASMModule();
Expand Down
16 changes: 9 additions & 7 deletions packages/bruno-js/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ const evaluateJsTemplateLiteral = (templateLiteral, context) => {
return undefined;
}

if (templateLiteral.startsWith('"') && templateLiteral.endsWith('"')) {
return templateLiteral.slice(1, -1);
}

if (templateLiteral.startsWith("'") && templateLiteral.endsWith("'")) {
return templateLiteral.slice(1, -1);
}
// This is commented out as part of the fix for #3758
// if (templateLiteral.startsWith('"') && templateLiteral.endsWith('"')) {
// return templateLiteral.slice(1, -1);
// }

// This is commented out as part of the fix for #3758
// if (templateLiteral.startsWith("'") && templateLiteral.endsWith("'")) {
// return templateLiteral.slice(1, -1);
// }

if (!isNaN(templateLiteral)) {
const number = Number(templateLiteral);
Expand Down

0 comments on commit 6abd063

Please sign in to comment.