diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index c781805b..6311d5b6 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -24,6 +24,8 @@ import CxChat from "../chat/CxChat"; import CxMask from "../mask/CxMask"; import CxVorpal from "../vorpal/CxVorpal"; +let skipValue = false; +const fileSourceFlag = "--file-source" function isJsonString(s: string) { try { @@ -35,12 +37,26 @@ function isJsonString(s: string) { return true; } -function transformation(commands: string[]):string[] { - const result:string[] = commands.map(transform); +function transformation(commands: string[]): string[] { + skipValue = false; // Reset the flag before processing + const result: string[] = commands.map(transform); return result; } function transform(n:string) { + +// in case the file name looks like this: 'var express require('express');.js' we won't delete "'" + if (skipValue) { + skipValue = false; + let r = ""; + if(n) r = n.replace(/["]/g, "").replace("/[, ]/g",","); + return r; + } + // If the current string is "--file-source", set the flag + if (n === fileSourceFlag) { + skipValue = true; + } + let r = ""; if(n) r = n.replace(/["']/g, "").replace("/[, ]/g",","); return r; diff --git a/src/tests/ScanTest.test.ts b/src/tests/ScanTest.test.ts index 56cf7c96..fb7b9a69 100644 --- a/src/tests/ScanTest.test.ts +++ b/src/tests/ScanTest.test.ts @@ -145,6 +145,16 @@ describe("ScanCreate cases", () => { expect(scanObject.status).toEqual(true); }); + it('ScanVorpal with complex name Successful case', async () => { + const auth = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await auth.scanVorpal("tsc/tests/data/var express = require('express';.js"); + console.log("Json object from scanVorpal successful case: " + JSON.stringify(cxCommandOutput)); + const scanObject = cxCommandOutput.payload.pop(); + expect(cxCommandOutput.payload).toBeDefined(); + expect(cxCommandOutput.exitCode).toBe(0); + expect(scanObject.status).toEqual(true); + }); + it('ScanVorpal Successful case with update version', async () => { const auth = new CxWrapper(cxScanConfig); const cxCommandOutput: CxCommandOutput = await auth.scanVorpal("tsc/tests/data/python-vul-file.py", true); diff --git a/tsc/tests/data/var express = require('express';.js b/tsc/tests/data/var express = require('express';.js new file mode 100644 index 00000000..11a74e4c --- /dev/null +++ b/tsc/tests/data/var express = require('express';.js @@ -0,0 +1 @@ +var password = "Jf9$gH!sD7#lq2nW";