fix: strip slash for pretty regexp

This commit is contained in:
ahabhgk 2024-07-04 15:36:24 +08:00
parent dd44b206a9
commit 515c0d3cd0
2 changed files with 5 additions and 5 deletions

View File

@ -185,13 +185,13 @@ class ContextModule extends Module {
/**
* @private
* @param {RegExp} regexString RegExp as a string
* @param {RegExp} regex RegExp
* @param {boolean=} stripSlash do we need to strip a slsh
* @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;
_prettyRegExp(regex, stripSlash = true) {
const regexString = stripSlash ? regex.source + regex.flags : regex + "";
return regexString.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"
);
});