Skip to content

Commit b153721

Browse files
knight.chenkeuby
authored andcommitted
fix(LazySourceCodeCache): escape question mark in file extension regex to prevent incorrect replacements
1 parent 7228d99 commit b153721

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/preset-umi/src/libs/folderCache/LazySourceCodeCache.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ export class LazySourceCodeCache {
188188
for (const f of files) {
189189
let newFile = join(this.cachePath, relative(this.srcPath, f));
190190

191-
newFile = newFile.replace(new RegExp(`${extname(newFile)}$`), '.js');
191+
const extRegexStr = extname(newFile)
192+
.replace('?', '\\?')
193+
.replace('.', '\\.');
194+
newFile = newFile.replace(new RegExp(`${extRegexStr}$`), '.js');
192195

193196
loaded[f] = readFileSync(newFile, 'utf-8');
194197
}

0 commit comments

Comments
 (0)