From 7214056deb05a0fb809d03b0f8ff079ac78bd866 Mon Sep 17 00:00:00 2001 From: Vogogna Dario Date: Mon, 10 Jun 2019 11:20:30 +0200 Subject: [PATCH] Remove usage of the 'eval' function #58 --- package.json | 4 ++-- src/grammar-parser/grammar-parser.jison | 9 +-------- test/integration/parsing/function.js | 6 ++++++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 68224957..dab832bd 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/src/grammar-parser/grammar-parser.jison b/src/grammar-parser/grammar-parser.jison index e5cb5066..5dd03a39 100644 --- a/src/grammar-parser/grammar-parser.jison +++ b/src/grammar-parser/grammar-parser.jison @@ -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); diff --git a/test/integration/parsing/function.js b/test/integration/parsing/function.js index 8d96dd33..0bcaf50e 100644 --- a/test/integration/parsing/function.js +++ b/test/integration/parsing/function.js @@ -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}); + }); });