1
0
Fork 0
forked from svrjs/svrjs

Change regular expression for createRegex() function

This commit is contained in:
Dorian Niemiec 2024-08-27 12:06:23 +02:00
parent fae1b661ed
commit ff66e26af0

View file

@ -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];