Browse Source

fixed issue when style attribute is undefined

Gildas 7 năm trước cách đây
mục cha
commit
e1f1b814e0

+ 2 - 2
lib/single-file/css-fonts-minifier.js

@@ -78,7 +78,7 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 				}
 				}
 			});
 			});
 			doc.querySelectorAll("[style]").forEach(element => {
 			doc.querySelectorAll("[style]").forEach(element => {
-				if (element.style.fontFamily) {
+				if (element.style && element.style.fontFamily) {
 					const fontFamilyNames = element.style.fontFamily.split(",").map(fontFamilyName => removeQuotes(fontFamilyName));
 					const fontFamilyNames = element.style.fontFamily.split(",").map(fontFamilyName => removeQuotes(fontFamilyName));
 					fontsInfo.used.push(fontFamilyNames);
 					fontsInfo.used.push(fontFamilyNames);
 				}
 				}
@@ -241,7 +241,7 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 		return stylesheetContent;
 		return stylesheetContent;
 	}
 	}
 
 
-	function processFontFaceRule(rule, fontInfo, stats) {		
+	function processFontFaceRule(rule, fontInfo, stats) {
 		const fontTest = (fontSource, format) => !fontSource.src.startsWith(EMPTY_URL_SOURCE) && fontSource.format == format;
 		const fontTest = (fontSource, format) => !fontSource.src.startsWith(EMPTY_URL_SOURCE) && fontSource.format == format;
 		let woffFontFound = fontInfo.find(fontSource => fontTest(fontSource, "woff2-variations"));
 		let woffFontFound = fontInfo.find(fontSource => fontTest(fontSource, "woff2-variations"));
 		if (!woffFontFound) {
 		if (!woffFontFound) {

+ 7 - 5
lib/single-file/css-rules-minifier.js

@@ -48,11 +48,13 @@ this.cssMinifier = this.cssMinifier || (() => {
 				log("  -- STARTED processStyleAttribute");
 				log("  -- STARTED processStyleAttribute");
 			}
 			}
 			doc.querySelectorAll("[style]").forEach(element => {
 			doc.querySelectorAll("[style]").forEach(element => {
-				const textContent = processStyleAttribute(element.style, mediaAllInfo);
-				if (textContent) {
-					element.setAttribute("style", textContent);
-				} else {
-					element.removeAttribute("style");
+				if (element.style) {
+					const textContent = processStyleAttribute(element.style, mediaAllInfo);
+					if (textContent) {
+						element.setAttribute("style", textContent);
+					} else {
+						element.removeAttribute("style");
+					}
 				}
 				}
 			});
 			});
 			if (DEBUG) {
 			if (DEBUG) {