Fixed detection of multiple consecutive CSS URLs without quotes (#4)

This commit is contained in:
Daniël van de Giessen
2018-12-30 06:36:17 +01:00
committed by yz-yu
parent 056b317116
commit 91e031844e
2 changed files with 9 additions and 2 deletions

View File

@@ -42,11 +42,12 @@ function extractOrigin(url: string): string {
return origin;
}
const URL_IN_CSS_REF = /url\((['"]|)([^'"]*)\1\)/gm;
const URL_IN_CSS_REF = /url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm;
const RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/;
const DATA_URI = /^(data:)([\w\/\+]+);(charset=[\w-]+|base64).*,(.*)/gi;
export function absoluteToStylesheet(cssText: string, href: string): string {
return cssText.replace(URL_IN_CSS_REF, (_1, _2, filePath) => {
return cssText.replace(URL_IN_CSS_REF, (_1, path1, path2, path3) => {
const filePath = path1 || path2 || path3;
if (!RELATIVE_PATH.test(filePath)) {
return `url('${filePath}')`;
}