Comparing version 1.0.0 to 1.1.0
var parse = require('ret'); | ||
var types = parse.types; | ||
module.exports = function (re) { | ||
module.exports = function (re, opts) { | ||
if (!opts) opts = {}; | ||
var replimit = opts.limit === undefined ? 25 : opts.limit; | ||
if (isRegExp(re)) re = re.source; | ||
@@ -11,6 +14,9 @@ else if (typeof re !== 'string') re = String(re); | ||
var reps = 0; | ||
return (function walk (node, starHeight) { | ||
if (node.type === types.REPETITION) { | ||
starHeight ++; | ||
reps ++; | ||
if (starHeight > 1) return false; | ||
if (reps > replimit) return false; | ||
} | ||
@@ -17,0 +23,0 @@ |
{ | ||
"name": "safe-regex", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "detect possibly catastrophic, exponential-time regular expressions", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -10,2 +10,3 @@ var safe = require('../'); | ||
/^\d+(1337|404)*\d+$/i, | ||
RegExp(Array(26).join('a?') + Array(26).join('a')), | ||
]; | ||
@@ -23,2 +24,3 @@ | ||
/^(a?){25}(a){25}$/, | ||
RegExp(Array(27).join('a?') + Array(27).join('a')), | ||
/(x+x+)+y/, | ||
@@ -39,13 +41,13 @@ /foo|(x+x+)+y/, | ||
var invalid = [ | ||
'*Oakland*', | ||
'hey(yoo))', | ||
'abcde(?>hellow)', | ||
'[abc' | ||
'*Oakland*', | ||
'hey(yoo))', | ||
'abcde(?>hellow)', | ||
'[abc' | ||
]; | ||
test('invalid regex', function (t) { | ||
t.plan(invalid.length); | ||
invalid.forEach(function (re) { | ||
t.equal(safe(re), false); | ||
}); | ||
t.plan(invalid.length); | ||
invalid.forEach(function (re) { | ||
t.equal(safe(re), false); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5870
81
66