From dcb5590842f3f9c07c3dd0336252d2dbf71e190d Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 7 Sep 2019 10:47:31 +0100 Subject: [PATCH] Clipper: Fixes #1851: Fixed error when trying to import certain pages using "Clip simplified page" feature --- ReactNativeClient/lib/services/rest/Api.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ReactNativeClient/lib/services/rest/Api.js b/ReactNativeClient/lib/services/rest/Api.js index 1ee2bc91d..d4cd3d852 100644 --- a/ReactNativeClient/lib/services/rest/Api.js +++ b/ReactNativeClient/lib/services/rest/Api.js @@ -652,10 +652,21 @@ class Api { const urlInfo = urls[imageUrl]; if (!urlInfo || !urlInfo.resource) return before + imageUrl + after; if (!(urlInfo.originalUrl in imageSizesIndexes)) imageSizesIndexes[urlInfo.originalUrl] = 0; - const imageSize = imageSizes[urlInfo.originalUrl][imageSizesIndexes[urlInfo.originalUrl]]; - imageSizesIndexes[urlInfo.originalUrl]++; - const resourceUrl = Resource.internalUrl(urlInfo.resource); + const resourceUrl = Resource.internalUrl(urlInfo.resource); + const imageSizesCollection = imageSizes[urlInfo.originalUrl]; + + if (!imageSizesCollection) { + // In some cases, we won't find the image size information for that particular URL. Normally + // it will only happen when using the "Clip simplified page" feature, which can modify the + // image URLs (for example it will select a smaller size resolution). In that case, it's + // fine to return the image as-is because it has already good dimensions. + return before + resourceUrl + after; + } + + const imageSize = imageSizesCollection[imageSizesIndexes[urlInfo.originalUrl]]; + imageSizesIndexes[urlInfo.originalUrl]++; + if (imageSize && (imageSize.naturalWidth !== imageSize.width || imageSize.naturalHeight !== imageSize.height)) { return ''; } else {