aboutsummaryrefslogtreecommitdiff
path: root/node_modules/regex-not/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/regex-not/index.js')
-rw-r--r--node_modules/regex-not/index.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/node_modules/regex-not/index.js b/node_modules/regex-not/index.js
index 8593d8b3a..02bfed4a8 100644
--- a/node_modules/regex-not/index.js
+++ b/node_modules/regex-not/index.js
@@ -1,6 +1,7 @@
'use strict';
var extend = require('extend-shallow');
+var safe = require('safe-regex');
/**
* The main export is a function that takes a `pattern` string and an `options` object.
@@ -41,7 +42,7 @@ toRegex.create = function(pattern, options) {
}
var opts = extend({}, options);
- if (opts && opts.contains === true) {
+ if (opts.contains === true) {
opts.strictNegate = false;
}
@@ -50,13 +51,18 @@ toRegex.create = function(pattern, options) {
var endChar = opts.endChar ? opts.endChar : '+';
var str = pattern;
- if (opts && opts.strictNegate === false) {
+ if (opts.strictNegate === false) {
str = '(?:(?!(?:' + pattern + ')).)' + endChar;
} else {
str = '(?:(?!^(?:' + pattern + ')$).)' + endChar;
}
- return open + str + close;
+ var res = open + str + close;
+ if (opts.safe === true && safe(res) === false) {
+ throw new Error('potentially unsafe regular expression: ' + res);
+ }
+
+ return res;
};
/**