Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/main/wrapper/ExecutionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/tests/ScanTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tsc/tests/data/var express = require('express';.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var password = "Jf9$gH!sD7#lq2nW";