From ccdd1ea96b4393312f5b31859cfa2861176a8db7 Mon Sep 17 00:00:00 2001 From: ymrdf <837856276@qq.com> Date: Sun, 12 Sep 2021 17:00:11 +0800 Subject: [PATCH] Fix the exception when get property from function's parameter --- index.js | 9 ++++++++- test/eval.js | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 92f4687..a34e50c 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,8 @@ var unparse = require('escodegen').generate; +// flag of function argument +var FUNCTION_ARGUMENT_FLAG = 'FUNCTION_ARGUMENT_FLAG'; + module.exports = function (ast, vars, opts) { if(!opts) opts = {}; var rejectAccessToMethodsOnFunctions = !opts.allowAccessToMethodsOnFunctions; @@ -129,6 +132,10 @@ module.exports = function (ast, vars, opts) { } if (node.property.type === 'Identifier' && !node.computed) { if (isUnsafeProperty(node.property.name)) return FAIL; + // don't execute when object or property are argument + if(noExecute && (obj === FUNCTION_ARGUMENT_FLAG || node.property.name === FUNCTION_ARGUMENT_FLAG)){ + return FUNCTION_ARGUMENT_FLAG + } return obj[node.property.name]; } var prop = walk(node.property, noExecute); @@ -161,7 +168,7 @@ module.exports = function (ast, vars, opts) { for(var i=0; i