Bläddra i källkod

fixed error when setting invalid attribute names

Gildas 7 år sedan
förälder
incheckning
d1a744853e
1 ändrade filer med 15 tillägg och 1 borttagningar
  1. 15 1
      lib/single-file/html-images-minifier.js

+ 15 - 1
lib/single-file/html-images-minifier.js

@@ -127,7 +127,21 @@ this.imagesMinifier = this.imagesMinifier || (() => {
 						const svgElement = doc.createElementNS(SVG_NS, "svg");
 						const svgElement = doc.createElementNS(SVG_NS, "svg");
 						const useElement = doc.createElementNS(SVG_NS, "use");
 						const useElement = doc.createElementNS(SVG_NS, "use");
 						svgElement.appendChild(useElement);
 						svgElement.appendChild(useElement);
-						imgElement.getAttributeNames().forEach(attributeName => attributeName != "src" && svgElement.setAttribute(attributeName, imgElement.getAttribute(attributeName)));
+						imgElement.getAttributeNames().forEach(attributeName => {
+							try {
+								if (attributeName != "src") {
+									svgElement.setAttribute(attributeName, imgElement.getAttribute(attributeName));
+								}
+							} catch (error) {
+								if (attributeName != "src") {
+									try {
+										svgElement.setAttributeNS(SVG_NS, attributeName, imgElement.getAttribute(attributeName));
+									} catch (error) {
+										/* ignored */
+									}
+								}
+							}
+						});
 						svgElement.setAttribute(TRANSFORMED_IMAGE_ATTRIBUTE, "");
 						svgElement.setAttribute(TRANSFORMED_IMAGE_ATTRIBUTE, "");
 						svgElement.setAttributeNS(SVG_NS, "viewBox", "0 0 " + width + " " + height);
 						svgElement.setAttributeNS(SVG_NS, "viewBox", "0 0 " + width + " " + height);
 						svgElement.setAttributeNS(SVG_NS, "width", imageData.clientWidth);
 						svgElement.setAttributeNS(SVG_NS, "width", imageData.clientWidth);