From 4d07aea1a2ba2f6bc629b73774459afe0bd37279 Mon Sep 17 00:00:00 2001 From: "jstephen@redhat.com" Date: Fri, 17 May 2024 10:55:35 -0400 Subject: [PATCH] Fix invalid image parameter crash Resolves: https://github.com/freeotp/freeotp-ios/issues/351 Resolves: https://github.com/freeotp/freeotp-ios/issues/340 --- FreeOTP/ImageDownloader.swift | 44 ++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/FreeOTP/ImageDownloader.swift b/FreeOTP/ImageDownloader.swift index cfa19a1..3c1d902 100644 --- a/FreeOTP/ImageDownloader.swift +++ b/FreeOTP/ImageDownloader.swift @@ -88,30 +88,32 @@ class ImageDownloader : NSObject { } func fromURL(_ url: URL, _ iv: UIImageView, completion: @escaping (UIImage) -> Void) { - switch url.scheme! { - case "file": - if let img = UIImage(contentsOfFile: url.path) { - return completion(img) - } + if let scheme = url.scheme { + switch scheme { + case "file": + if let img = UIImage(contentsOfFile: url.path) { + return completion(img) + } - case "assets-library": - return fromALAsset(url, completion: completion) + case "assets-library": + return fromALAsset(url, completion: completion) + + case "http": + fallthrough + case "https": + iv.sd_setImage(with: url, placeholderImage: self.DEFAULT, + completed: { (image, error, cacheType, url) in + if let image { + completion(image) + } + }) + return + default: + break + } - case "http": - fallthrough - case "https": - iv.sd_setImage(with: url, placeholderImage: self.DEFAULT, - completed: { (image, error, cacheType, url) in - if let image { - completion(image) - } - }) - return - default: - break + return completion(DEFAULT) } - - return completion(DEFAULT) } func fromURI(_ uri: String?, _ iv: UIImageView, completion: @escaping (UIImage) -> Void) {