陶泥儿 H5 产物校验覆盖单引号根路径引用
- assertH5Root 的属性正则同时匹配单/双引号并容忍 = 两侧空白,避免手写/插件 HTML 漏检
This commit is contained in:
+5
-1
@@ -52,7 +52,11 @@ export function assertH5Root(outDir) {
|
||||
}
|
||||
|
||||
const html = readFileSync(htmlPath, 'utf8');
|
||||
const absoluteRefs = [...html.matchAll(/\s(?:src|href)="(\/[^"]*)"/gi)].map((match) => match[1]);
|
||||
// 同时匹配单/双引号属性,且容忍 `=` 两侧空白;只看双引号会漏掉手写 HTML 或插件产物里的
|
||||
// `src='/app.js'`,让误配 base 的产物通过校验、上传后整站 404。
|
||||
const absoluteRefs = [...html.matchAll(/\s(?:src|href)\s*=\s*(["'])(\/[^"']*)\1/gi)].map(
|
||||
(match) => match[2],
|
||||
);
|
||||
if (absoluteRefs.length > 0) {
|
||||
throw new Error(
|
||||
`index.html 仍引用根路径资源(${absoluteRefs.join(', ')});`
|
||||
|
||||
Reference in New Issue
Block a user