Skip to content

Commit 3377771

Browse files
Vorpal in VsCode is unable to run scans in Sample with complex names (AST-62777) (#736)
* Vorpal in VsCode is unable to run scans in sampes with complex names * v2 To talk with Tiago, if necessary, we'll do it this way * Update ExecutionService.ts * Update ExecutionService.ts * add test
1 parent 775e172 commit 3377771

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/main/wrapper/ExecutionService.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import CxChat from "../chat/CxChat";
2424
import CxMask from "../mask/CxMask";
2525
import CxVorpal from "../vorpal/CxVorpal";
2626

27+
let skipValue = false;
28+
const fileSourceFlag = "--file-source"
2729

2830
function isJsonString(s: string) {
2931
try {
@@ -35,12 +37,26 @@ function isJsonString(s: string) {
3537
return true;
3638
}
3739

38-
function transformation(commands: string[]):string[] {
39-
const result:string[] = commands.map(transform);
40+
function transformation(commands: string[]): string[] {
41+
skipValue = false; // Reset the flag before processing
42+
const result: string[] = commands.map(transform);
4043
return result;
4144
}
4245

4346
function transform(n:string) {
47+
48+
// in case the file name looks like this: 'var express require('express');.js' we won't delete "'"
49+
if (skipValue) {
50+
skipValue = false;
51+
let r = "";
52+
if(n) r = n.replace(/["]/g, "").replace("/[, ]/g",",");
53+
return r;
54+
}
55+
// If the current string is "--file-source", set the flag
56+
if (n === fileSourceFlag) {
57+
skipValue = true;
58+
}
59+
4460
let r = "";
4561
if(n) r = n.replace(/["']/g, "").replace("/[, ]/g",",");
4662
return r;

src/tests/ScanTest.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ describe("ScanCreate cases", () => {
145145
expect(scanObject.status).toEqual(true);
146146
});
147147

148+
it('ScanVorpal with complex name Successful case', async () => {
149+
const auth = new CxWrapper(cxScanConfig);
150+
const cxCommandOutput: CxCommandOutput = await auth.scanVorpal("tsc/tests/data/var express = require('express';.js");
151+
console.log("Json object from scanVorpal successful case: " + JSON.stringify(cxCommandOutput));
152+
const scanObject = cxCommandOutput.payload.pop();
153+
expect(cxCommandOutput.payload).toBeDefined();
154+
expect(cxCommandOutput.exitCode).toBe(0);
155+
expect(scanObject.status).toEqual(true);
156+
});
157+
148158
it('ScanVorpal Successful case with update version', async () => {
149159
const auth = new CxWrapper(cxScanConfig);
150160
const cxCommandOutput: CxCommandOutput = await auth.scanVorpal("tsc/tests/data/python-vul-file.py", true);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var password = "Jf9$gH!sD7#lq2nW";

0 commit comments

Comments
 (0)