diff --git a/src/utils/createRegex.js b/src/utils/createRegex.js index 987f8a0..c18cfd9 100644 --- a/src/utils/createRegex.js +++ b/src/utils/createRegex.js @@ -1,7 +1,11 @@ const os = require("os"); 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); const searchString = regexStrMatch[1]; let modifiers = regexStrMatch[2];