diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/regex-not/index.js | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
Diffstat (limited to 'node_modules/regex-not/index.js')
-rw-r--r-- | node_modules/regex-not/index.js | 12 |
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; }; /** |