complately update relative path regexp

This commit is contained in:
Yanzhen Yu
2018-11-26 17:42:52 +08:00
parent aca8207db9
commit f73bad21e5
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] === '/') {