forked from svrjs/svrjs
Change regular expression for createRegex() function
This commit is contained in:
parent
fae1b661ed
commit
ff66e26af0
1 changed files with 5 additions and 1 deletions
|
@ -1,7 +1,11 @@
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
|
|
||||||
function createRegex(regex, isPath) {
|
function createRegex(regex, isPath) {
|
||||||
const regexStrMatch = regex.match(/^\/((?:\\.|[^/\\])*)\/([a-zA-Z0-9]*)$/);
|
// The new regular expression supports single unescaped "/" within [], but not two unescaped "/".
|
||||||
|
// We needed to do it, because it's very hard to create the regex that matches two unescaped "/" within "[]" without ReDoS.
|
||||||
|
const regexStrMatch = regex.match(
|
||||||
|
/^\/((?:\\.|\/+(?:(?:\\.|[^\]\\/])*\])|[^/\\])*)\/([a-zA-Z0-9]*)$/,
|
||||||
|
);
|
||||||
if (!regexStrMatch) throw new Error("Invalid regular expression: " + regex);
|
if (!regexStrMatch) throw new Error("Invalid regular expression: " + regex);
|
||||||
const searchString = regexStrMatch[1];
|
const searchString = regexStrMatch[1];
|
||||||
let modifiers = regexStrMatch[2];
|
let modifiers = regexStrMatch[2];
|
||||||
|
|
Reference in a new issue