Explorar el Código

be more tolerant with favicon content type

Gildas hace 7 años
padre
commit
6dc6515286
Se han modificado 1 ficheros con 14 adiciones y 4 borrados
  1. 14 4
      lib/single-file/single-file-core.js

+ 14 - 4
lib/single-file/single-file-core.js

@@ -662,7 +662,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 		async processPageResources() {
 			const resourcePromises = [
-				DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("link[href][rel*=\"icon\"]"), "href", PREFIX_DATA_URI_IMAGE, this.baseURI, this.options, this.batchRequest, false, true),
+				DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("link[href][rel*=\"icon\"]"), "href", "data:", this.baseURI, this.options, this.batchRequest, false, true),
 				DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("object[type=\"image/svg+xml\"], object[type=\"image/svg-xml\"]"), "data", PREFIX_DATA_URI_IMAGE_SVG, this.baseURI, this.options, this.batchRequest),
 				DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("img[src], input[src][type=image]"), "src", PREFIX_DATA_URI_IMAGE, this.baseURI, this.options, this.batchRequest, true),
 				DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("embed[src*=\".svg\"]"), "src", PREFIX_DATA_URI_IMAGE_SVG, this.baseURI, this.options, this.batchRequest),
@@ -680,9 +680,13 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			}
 			await resourcePromises;
 			if (this.options.removeAlternativeImages) {
-				const shortcutIcons = Array.from(this.doc.querySelectorAll("link[href][rel=\"icon\"], link[href][rel=\"shortcut icon\"]"));
-				shortcutIcons.sort((linkElement1, linkElement2) => (parseInt(linkElement2.sizes, 10) || 16) - (parseInt(linkElement1.sizes, 10) || 16));
-				const shortcutIcon = shortcutIcons[0];
+				let shortcutIcon = findShortcutIcon(Array.from(this.doc.querySelectorAll("link[href][rel=\"icon\"], link[href][rel=\"shortcut icon\"]")));
+				if (!shortcutIcon) {
+					shortcutIcon = findShortcutIcon(Array.from(this.doc.querySelectorAll("link[href][rel*=\"icon\"]")));
+					if (shortcutIcon) {
+						shortcutIcon.rel = "icon";
+					}
+				}
 				if (shortcutIcon) {
 					this.doc.querySelectorAll("link[href][rel*=\"icon\"]").forEach(linkElement => {
 						if (linkElement != shortcutIcon) {
@@ -691,6 +695,12 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 					});
 				}
 			}
+
+			function findShortcutIcon(shortcutIcons) {
+				shortcutIcons = shortcutIcons.filter(linkElement => linkElement.href != EMPTY_IMAGE);
+				shortcutIcons.sort((linkElement1, linkElement2) => (parseInt(linkElement2.sizes, 10) || 16) - (parseInt(linkElement1.sizes, 10) || 16));
+				return shortcutIcons[0];
+			}
 		}
 
 		async resolveStylesheetURLs() {