Ver Fonte

remove pre* link elements if needed

Gildas há 7 anos atrás
pai
commit
6b2f33e9f2
1 ficheiros alterados com 8 adições e 1 exclusões
  1. 8 1
      lib/single-file/single-file-core.js

+ 8 - 1
lib/single-file/single-file-core.js

@@ -315,7 +315,14 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			this.stats.set("discarded", "objects", objectElements.length);
 			objectElements.forEach(element => element.remove());
 			const replacedAttributeValue = this.doc.querySelectorAll("link[rel~=preconnect], link[rel~=prerender], link[rel~=dns-prefetch], link[rel~=preload], link[rel~=prefetch]");
-			replacedAttributeValue.forEach(element => element.setAttribute("rel", element.getAttribute("rel").replace(/(preconnect|prerender|dns-prefetch|preload|prefetch)/g, "")));
+			replacedAttributeValue.forEach(element => {
+				const relValue = element.getAttribute("rel").replace(/(preconnect|prerender|dns-prefetch|preload|prefetch)/g, "").trim();
+				if (relValue.length) {
+					element.setAttribute("rel", relValue);
+				} else {
+					element.remove();
+				}
+			});
 			this.doc.querySelectorAll("meta[http-equiv=\"content-security-policy\"").forEach(element => element.remove());
 			this.doc.querySelectorAll("a[ping]").forEach(element => element.removeAttribute("ping"));
 			if (this.options.removeScripts) {