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/to-regex/index.js | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
Diffstat (limited to 'node_modules/to-regex/index.js')
-rw-r--r-- | node_modules/to-regex/index.js | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/node_modules/to-regex/index.js b/node_modules/to-regex/index.js index 9c93def8c..a87d01591 100644 --- a/node_modules/to-regex/index.js +++ b/node_modules/to-regex/index.js @@ -1,5 +1,6 @@ 'use strict'; +var safe = require('safe-regex'); var define = require('define-property'); var extend = require('extend-shallow'); var not = require('regex-not'); @@ -86,10 +87,16 @@ function makeRe(pattern, options) { if (opts.negate || typeof opts.strictNegate === 'boolean') { pattern = not.create(pattern, opts); } + var str = open + '(?:' + pattern + ')' + close; regex = new RegExp(str, flags); + + if (opts.safe === true && safe(regex) === false) { + throw new Error('potentially unsafe regular expression: ' + regex.source); + } + } catch (err) { - if (opts.strictErrors === true) { + if (opts.strictErrors === true || opts.safe === true) { err.key = key; err.pattern = pattern; err.originalOptions = options; @@ -105,18 +112,18 @@ function makeRe(pattern, options) { } if (opts.cache !== false) { - cacheRegex(regex, key, pattern, opts); + memoize(regex, key, pattern, opts); } return regex; } /** - * Cache generated regex. This can result in dramatic speed improvements + * Memoize generated regex. This can result in dramatic speed improvements * and simplify debugging by adding options and pattern to the regex. It can be * disabled by passing setting `options.cache` to false. */ -function cacheRegex(regex, key, pattern, options) { +function memoize(regex, key, pattern, options) { define(regex, 'cached', true); define(regex, 'pattern', pattern); define(regex, 'options', options); |