Skip to content

Commit

Permalink
Remove usage of the 'eval' function handsontable#58
Browse files Browse the repository at this point in the history
  • Loading branch information
Vogogna Dario committed Jun 10, 2019
1 parent 125d64d commit 7214056
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"generate-parser": "cd src/grammar-parser && jison grammar-parser.jison",
"release": "generate-release",
"prepare": "npm run build",
"prepublishOnly": "npm run clean && npm run check && npm run build && check-es3-syntax lib/ dist/ --kill --print"
"prepublishOnly": "npm run clean && npm run check && npm run build"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -83,7 +83,7 @@
"webpack": "^3.2.0"
},
"dependencies": {
"@handsontable/formulajs": "^2.0.0",
"@handsontable/formulajs": "^2.0.1",
"tiny-emitter": "^2.0.1"
},
"jest": {
Expand Down
9 changes: 1 addition & 8 deletions src/grammar-parser/grammar-parser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,7 @@ expseq
$$ = [$1];
}
| ARRAY {
var result = [];
var arr = eval("[" + yytext + "]");
arr.forEach(function(item) {
result.push(item);
});
$$ = result;
$$ = yy.trimEdges(yytext).split(',');
}
| expseq ';' expression {
$1.push($3);
Expand Down
6 changes: 6 additions & 0 deletions test/integration/parsing/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ describe('.parse() custom function', () => {
expect(parser.parse('SUM(4, ADD_5(1))')).toMatchObject({error: null, result: 10});
expect(parser.parse('GET_LETTER("Some string", 3)')).toMatchObject({error: null, result: 'm'});
});

it('should evaluate function with arguments passed as an stringified array', () => {
expect(parser.parse('SUM([])')).toMatchObject({error: null, result: 0});
expect(parser.parse('SUM([1])')).toMatchObject({error: null, result: 1});
expect(parser.parse('SUM([1,2,3])')).toMatchObject({error: null, result: 6});
});
});

0 comments on commit 7214056

Please sign in to comment.