Explorar el Código

fixed case where URLs in CSS can't be parsed

Gildas hace 7 años
padre
commit
4e66c002a4
Se han modificado 2 ficheros con 20 adiciones y 12 borrados
  1. 10 6
      lib/single-file/css-fonts-minifier.js
  2. 10 6
      lib/single-file/single-file-core.js

+ 10 - 6
lib/single-file/css-fonts-minifier.js

@@ -176,13 +176,17 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 				for (; node && !(node.data.type == "Operator" && node.data.value == ","); node = node.prev);
 				for (; node && !(node.data.type == "Operator" && node.data.value == ","); node = node.prev);
 				return node;
 				return node;
 			};
 			};
-			for (let node = font.data.value.children.tail; node && (node.data.type != "WhiteSpace" || findPreviousComma(node)); node = node.prev) {
-				if (node.data.type == "Operator" && node.data.value == "," && familyName) {
-					fontFamilyNames.push(getFontFamily(familyName));
-					familyName = "";
-				} else {
-					familyName = cssTree.generate(node.data) + familyName;
+			if (font.data.value.children) {
+				for (let node = font.data.value.children.tail; node && (node.data.type != "WhiteSpace" || findPreviousComma(node)); node = node.prev) {
+					if (node.data.type == "Operator" && node.data.value == "," && familyName) {
+						fontFamilyNames.push(getFontFamily(familyName));
+						familyName = "";
+					} else {
+						familyName = cssTree.generate(node.data) + familyName;
+					}
 				}
 				}
+			} else {
+				familyName = cssTree.generate(font.data.value);
 			}
 			}
 			if (familyName) {
 			if (familyName) {
 				fontFamilyNames.push(getFontFamily(familyName));
 				fontFamilyNames.push(getFontFamily(familyName));

+ 10 - 6
lib/single-file/single-file-core.js

@@ -1244,11 +1244,15 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 									if (!validResource) {
 									if (!validResource) {
 										content = EMPTY_DATA_URI;
 										content = EMPTY_DATA_URI;
 									}
 									}
-									declaration.value.children.forEach(token => {
-										if (token.type == "Url" && DOM.removeQuotes(DomUtil.getCSSValue(token.value)) == originalResourceURL) {
-											token.value.value = content;
-										}
-									});
+									if (declaration.value.children) {
+										declaration.value.children.forEach(token => {
+											if (token.type == "Url" && DOM.removeQuotes(DomUtil.getCSSValue(token.value)) == originalResourceURL) {
+												token.value.value = content;
+											}
+										});
+									} else {
+										declaration.value = "url(" + DOM.removeQuotes(DomUtil.getCSSValue(content)) + ")";
+									}
 								}
 								}
 							}
 							}
 						}));
 						}));
@@ -1259,7 +1263,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 
 		static async processStyle(declarations, baseURI, options, cssVariables, batchRequest) {
 		static async processStyle(declarations, baseURI, options, cssVariables, batchRequest) {
 			await Promise.all(declarations.map(async declaration => {
 			await Promise.all(declarations.map(async declaration => {
-				if (declaration.type == "Declaration") {
+				if (declaration.type == "Declaration" && declaration.value.children) {
 					const urlFunctions = DomUtil.getUrlFunctions(DomUtil.getCSSValue(declaration.value));
 					const urlFunctions = DomUtil.getUrlFunctions(DomUtil.getCSSValue(declaration.value));
 					await Promise.all(urlFunctions.map(async urlFunction => {
 					await Promise.all(urlFunctions.map(async urlFunction => {
 						const originalResourceURL = DomUtil.matchURL(urlFunction);
 						const originalResourceURL = DomUtil.matchURL(urlFunction);