Merge pull request #11471 from Adityaperiwal/bugfix/ContextModuleRegex

refactor regex
This commit is contained in:
Tobias Koppers 2021-01-04 11:51:54 +01:00 committed by GitHub
commit 7412e71ba5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -144,7 +144,9 @@ class ContextModule extends Module {
prettyRegExp(regexString) {
// remove the "/" at the front and the beginning
// "/foo/" -> "foo"
return regexString.substring(1, regexString.length - 1);
return regexString
.substring(1, regexString.length - 1)
.replace(/!/g, "%21");
}
_createIdentifier() {

View File

@ -0,0 +1,21 @@
expect.extend({
toBeValidModuleId(received, moduleIdString) {
const pass = typeof received === "number" || received === moduleIdString;
if (pass) {
return {
message: () => `expected ${received} not to be a valid module id`,
pass: true
};
} else {
return {
message: () => `expected ${received} to be a valid module id`,
pass: false
};
}
}
});
it("should replace ! with %21 in the module id string of the context module", function () {
const moduleId = require.context("./folder", true, /^(?!file1\.js$).*$/i, "lazy").id;
expect(moduleId).toBeValidModuleId("./context/issue-10969/folder lazy recursive ^(?%21file1\\.js$).*$/");
});