complately update relative path regexp

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent cf54d7dab5
commit cdedca1716
3 changed files with 9 additions and 2 deletions

View File

@@ -43,9 +43,10 @@ function extractOrigin(url: string): string {
}
const URL_IN_CSS_REF = /url\((['"]|)([^'"]*)\1\)/gm;
const RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/;
export function absoluteToStylesheet(cssText: string, href: string): string {
return cssText.replace(URL_IN_CSS_REF, (_1, _2, filePath) => {
if (!/^[./]/.test(filePath)) {
if (!RELATIVE_PATH.test(filePath)) {
return `url('${filePath}')`;
}
if (filePath[0] === '/') {