detect-unsafe-regexp.js 614 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const RuleTester = require('eslint').RuleTester;
  3. const tester = new RuleTester();
  4. const ruleName = 'detect-unsafe-regex';
  5. const Rule = require(`../rules/${ruleName}`);
  6. tester.run(ruleName, Rule, {
  7. valid: [{ code: '/^\d+1337\d+$/' }],
  8. invalid: [
  9. {
  10. code: '/(x+x+)+y/',
  11. errors: [{ message: 'Unsafe Regular Expression' }]
  12. }
  13. ]
  14. });
  15. tester.run(`${ruleName} (new RegExp)`, Rule, {
  16. valid: [{ code: 'new RegExp(\'^\d+1337\d+$\')' }],
  17. invalid: [
  18. {
  19. code: 'new RegExp(\'x+x+)+y\')',
  20. errors: [{ message: 'Unsafe Regular Expression (new RegExp)' }]
  21. }
  22. ]
  23. });