Skip to content

Commit 63970df

Browse files
budnixrbeitra
authored andcommitted
Remove usage of the 'eval' function (handsontable#58)
* Remove usage of the 'eval' function * Update formulajs module
1 parent 1ed4012 commit 63970df

File tree

4 files changed

+8
-5082
lines changed

4 files changed

+8
-5082
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
"build:umd": "cross-env BABEL_ENV=commonjs NODE_ENV=development webpack src/index.js dist/formula-parser.js",
2020
"generate-parser": "cd src/grammar-parser && jison grammar-parser.jison",
2121
"release": "generate-release",
22-
"prepublish": "npm run clean && npm run check && npm run build && check-es3-syntax lib/ dist/ --kill --print",
23-
"prepare": "npm run clean && npm run check && npm run build && check-es3-syntax lib/ dist/ --kill --print"
22+
"prepublish": "npm run clean && npm run check && npm run build"
2423
},
2524
"repository": {
2625
"type": "git",

src/grammar-parser/grammar-parser.jison

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,7 @@ expseq
143143
$$ = [$1];
144144
}
145145
| ARRAY {
146-
var result = [];
147-
var arr = eval("[" + yytext + "]");
148-
149-
arr.forEach(function(item) {
150-
result.push(item);
151-
});
152-
153-
$$ = result;
146+
$$ = yy.trimEdges(yytext).split(',');
154147
}
155148
| expseq ';' expression {
156149
$1.push($3);

test/integration/parsing/function.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ describe('.parse() custom function', () => {
2424
expect(parser.parse('SUM(4, ADD_5(1))')).toMatchObject({error: null, result: 10});
2525
expect(parser.parse('GET_LETTER("Some string", 3)')).toMatchObject({error: null, result: 'm'});
2626
});
27+
28+
it('should evaluate function with arguments passed as an stringified array', () => {
29+
expect(parser.parse('SUM([])')).toMatchObject({error: null, result: 0});
30+
expect(parser.parse('SUM([1])')).toMatchObject({error: null, result: 1});
31+
expect(parser.parse('SUM([1,2,3])')).toMatchObject({error: null, result: 6});
32+
});
2733
});

0 commit comments

Comments
 (0)