Skip to content

Commit

Permalink
Remove usage of the 'eval' function (handsontable#58)
Browse files Browse the repository at this point in the history
* Remove usage of the 'eval' function
* Update formulajs module
  • Loading branch information
budnix authored and rbeitra committed Nov 28, 2019
1 parent e836345 commit dcdb702
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack src/index.js dist/formula-parser.js",
"generate-parser": "cd src/grammar-parser && jison grammar-parser.jison",
"release": "generate-release",
"prepublish": "npm run clean && npm run check && npm run build && check-es3-syntax lib/ dist/ --kill --print",
"prepare": "npm run clean && npm run check && npm run build && check-es3-syntax lib/ dist/ --kill --print"
"prepublish": "npm run clean && npm run check && npm run build"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -82,7 +81,7 @@
"webpack": "^3.2.0"
},
"dependencies": {
"@riffyn/formulajs": "^1.3.3",
"@riffyn/formulajs": "^1.3.4-beta1",
"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 @@ -143,14 +143,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 dcdb702

Please sign in to comment.