fix: strip slash for pretty regexp

This commit is contained in:
Alexander Akait 2024-07-10 19:46:22 +03:00 committed by GitHub
commit ae0393f230
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -190,8 +190,10 @@ class ContextModule extends Module {
* @returns {string} pretty RegExp
*/
_prettyRegExp(regexString, stripSlash = true) {
const str = (regexString + "").replace(/!/g, "%21").replace(/\|/g, "%7C");
return stripSlash ? str.substring(1, str.length - 1) : str;
const str = stripSlash
? regexString.source + regexString.flags
: regexString + "";
return str.replace(/!/g, "%21").replace(/\|/g, "%7C");
}
_createIdentifier() {

View File

@ -7,6 +7,6 @@ it("should replace ! with %21 in the module id string of the context module", fu
).id;
if (typeof moduleId !== "number")
expect(moduleId).toBe(
"./context/issue-10969/folder lazy recursive ^(?%21file1\\.js$).*$/"
"./context/issue-10969/folder lazy recursive ^(?%21file1\\.js$).*$i"
);
});