Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: escape question mark in file extension regex to prevent incorrect replacements#13166

Open
keuby wants to merge 1 commit into
umijs:masterfrom
keuby:fix-lazy-source-code-cache
Open

fix: escape question mark in file extension regex to prevent incorrect replacements#13166
keuby wants to merge 1 commit into
umijs:masterfrom
keuby:fix-lazy-source-code-cache

Conversation

@keuby

@keuby keuby commented Oct 28, 2025

Copy link
Copy Markdown

对于 vite bundler 构建时,会使用 ?url 的方式导入文件 url,例如如下场景

import { createFromIconfontCN } from '@ant-design/icons';
import iconfontUrl from './font_5036736_flr7joicve?url';

export const Iconfont = createFromIconfontCN({
  scriptUrl: iconfontUrl,
});

for (const f of files) {
let newFile = join(this.cachePath, relative(this.srcPath, f));
newFile = newFile.replace(new RegExp(`${extname(newFile)}$`), '.js');
loaded[f] = readFileSync(newFile, 'utf-8');
}

此时 189 行 newFile 的值会为 path/to/font_5036736_flr7joicve?url,由于 ? 在正则表达式中存在特殊含义,191 行中通过 extname 方法返回值构建的正则表达式为 /.js?url/ 并不能正确替换为 .js,正确的正则表达式应该为 /\.js\?url/

@vercel

vercel Bot commented Oct 28, 2025

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the chencheng's projects Team on Vercel.

A member of the Team first needs to authorize it.

@keuby keuby force-pushed the fix-lazy-source-code-cache branch from b153721 to 48304f5 Compare October 28, 2025 06:01
@keuby keuby force-pushed the fix-lazy-source-code-cache branch from 48304f5 to cd86d47 Compare October 28, 2025 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant