Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

safe-regex

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

safe-regex - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

8

index.js
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 @@

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc