close #24 css text can be null
This commit is contained in:
@@ -68,8 +68,13 @@ function extractOrigin(url: string): string {
|
|||||||
const URL_IN_CSS_REF = /url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm;
|
const URL_IN_CSS_REF = /url\((?:'([^']*)'|"([^"]*)"|([^)]*))\)/gm;
|
||||||
const RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/;
|
const RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/).*/;
|
||||||
const DATA_URI = /^(data:)([\w\/\+\-]+);(charset=[\w-]+|base64).*,(.*)/i;
|
const DATA_URI = /^(data:)([\w\/\+\-]+);(charset=[\w-]+|base64).*,(.*)/i;
|
||||||
export function absoluteToStylesheet(cssText: string, href: string): string {
|
export function absoluteToStylesheet(
|
||||||
return cssText.replace(URL_IN_CSS_REF, (origin, path1, path2, path3) => {
|
cssText: string | null,
|
||||||
|
href: string,
|
||||||
|
): string {
|
||||||
|
return (cssText || '').replace(
|
||||||
|
URL_IN_CSS_REF,
|
||||||
|
(origin, path1, path2, path3) => {
|
||||||
const filePath = path1 || path2 || path3;
|
const filePath = path1 || path2 || path3;
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
return origin;
|
return origin;
|
||||||
@@ -96,7 +101,8 @@ export function absoluteToStylesheet(cssText: string, href: string): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return `url('${stack.join('/')}')`;
|
return `url('${stack.join('/')}')`;
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAbsoluteSrcsetString(doc: Document, attributeValue: string) {
|
function getAbsoluteSrcsetString(doc: Document, attributeValue: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user