Skip to content

Commit

Permalink
fix: created two regex expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivansh-yadav13 committed Feb 22, 2022
1 parent 86e2add commit de5f2f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/util/util.ts
Expand Up @@ -104,13 +104,12 @@ function writeFile(path: string, file: string, encoding?: string): any {
});
}

const evalReg = new RegExp(/\beval\(([^),]*)\)/g);
const evalRegG = new RegExp(/\beval\(([^),]*)\)/g);
const evalReg = new RegExp(/\beval\(([^),]*)\)/);

// hasEval determine whether matcher contains function eval
function hasEval(s: string): boolean {
const res: boolean = evalReg.test(s);
evalReg.lastIndex = 0;
return res;
return evalReg.test(s);
}

// replaceEval replace function eval with the value of its parameters
Expand All @@ -120,7 +119,7 @@ function replaceEval(s: string, ruleName: string, rule: string): string {

// getEvalValue returns the parameters of function eval
function getEvalValue(s: string): string[] {
const subMatch = s.match(evalReg);
const subMatch = s.match(evalRegG);
const rules: string[] = [];
if (!subMatch) {
return [];
Expand Down
1 change: 1 addition & 0 deletions test/util.test.ts
Expand Up @@ -150,6 +150,7 @@ test('test globMatch', () => {
});

test('test hasEval', () => {
expect(util.hasEval('eval() && a && b && c')).toEqual(true);
expect(util.hasEval('eval() && a && b && c')).toEqual(true);
expect(util.hasEval('eval) && a && b && c')).toEqual(false);
expect(util.hasEval('eval)( && a && b && c')).toEqual(false);
Expand Down

0 comments on commit de5f2f4

Please sign in to comment.