Browse Source

fixed issue when image is not found

Gildas 7 years ago
parent
commit
a57a7944e9
2 changed files with 12 additions and 10 deletions
  1. 11 9
      lib/single-file/doc-helper.js
  2. 1 1
      lib/single-file/single-file-core.js

+ 11 - 9
lib/single-file/doc-helper.js

@@ -160,15 +160,17 @@ this.docHelper = this.docHelper || (() => {
 				if (tagName == "img") {
 					imageElement = element;
 				}
-				imageData.source = {
-					clientWidth: imageElement.clientWidth,
-					clientHeight: imageElement.clientHeight,
-					naturalWidth: imageElement.naturalWidth,
-					naturalHeight: imageElement.naturalHeight,
-					width: imageElement.width,
-					height: imageElement.height,
-					src: (!imageElement.currentSrc.startsWith("data:") && imageElement.currentSrc) || (!imageElement.src.startsWith("data:") && imageElement.src)
-				};
+				if (imageElement) {
+					imageData.source = {
+						clientWidth: imageElement.clientWidth,
+						clientHeight: imageElement.clientHeight,
+						naturalWidth: imageElement.naturalWidth,
+						naturalHeight: imageElement.naturalHeight,
+						width: imageElement.width,
+						height: imageElement.height,
+						src: (!imageElement.currentSrc.startsWith("data:") && imageElement.currentSrc) || (!imageElement.src.startsWith("data:") && imageElement.src)
+					};
+				}
 				data.push(imageData);
 			});
 			return data;

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

@@ -484,7 +484,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 					}
 					if (tagName == "picture") {
 						const imageElement = element.querySelector("img");
-						if (imageData.source.src && imageData.source.naturalWidth > 1 && imageData.source.naturalHeight > 1) {
+						if (imageData.source && imageData.source.src && imageData.source.naturalWidth > 1 && imageData.source.naturalHeight > 1) {
 							imageElement.removeAttribute("srcset");
 							imageElement.removeAttribute("sizes");
 							imageElement.src = imageData.source.src;