Skip to content

Commit

Permalink
fix: Ensure empty eval() doesn't crash detect-eval-with-expression (#139
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nzakas authored Feb 14, 2024
1 parent c73effd commit 8a7c7db
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions rules/detect-eval-with-expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ module.exports = {
url: 'https://github.com/eslint-community/eslint-plugin-security/blob/main/docs/rules/detect-eval-with-expression.md',
},
},
create: function (context) {
create(context) {
return {
CallExpression: function (node) {
if (node.callee.name === 'eval' && node.arguments[0].type !== 'Literal') {
CallExpression(node) {
if (node.callee.name === 'eval' && node.arguments.length && node.arguments[0].type !== 'Literal') {
context.report({ node: node, message: `eval with argument of type ${node.arguments[0].type}` });
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/rules/detect-eval-with-expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const tester = new RuleTester();
const ruleName = 'detect-eval-with-expression';

tester.run(ruleName, require(`../../rules/${ruleName}`), {
valid: [{ code: "eval('alert()')" }],
valid: [{ code: "eval('alert()')" }, { code: 'eval("some nefarious code");' }, { code: 'eval()' }],
invalid: [
{
code: 'eval(a);',
Expand Down

0 comments on commit 8a7c7db

Please # to comment.