diff --git a/pass/Controllers/PasswordDetailTableViewController.swift b/pass/Controllers/PasswordDetailTableViewController.swift index 16a9f95..a032a94 100644 --- a/pass/Controllers/PasswordDetailTableViewController.swift +++ b/pass/Controllers/PasswordDetailTableViewController.swift @@ -143,9 +143,9 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni indicator.stopAnimating() indicatorLable.isHidden = true editUIBarButtonItem.isEnabled = true - if let url = password.getURL() { + if let urlString = password.getURLString() { if self.passwordEntity?.image == nil{ - self.updatePasswordImage(url: url) + self.updatePasswordImage(urlString: urlString) } } } @@ -268,7 +268,25 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni } } - func updatePasswordImage(url: String) { + func updatePasswordImage(urlString: String) { + var newUrlString = urlString + if urlString.lowercased().hasPrefix("http://") { + // try to replace http url to https url + newUrlString = urlString.replacingOccurrences(of: "http://", + with: "https://", + options: .caseInsensitive, + range: urlString.range(of: "http://")) + } else if urlString.lowercased().hasPrefix("https://") { + // do nothing here + } else { + // if a url does not start with http or https, try to add https + newUrlString = "https://\(urlString)" + } + + guard let url = URL(string: newUrlString) else { + return + } + do { try FavIcon.downloadPreferred(url) { [weak self] result in switch result { diff --git a/pass/Models/Password.swift b/pass/Models/Password.swift index 5e202e8..25d20bb 100644 --- a/pass/Models/Password.swift +++ b/pass/Models/Password.swift @@ -73,7 +73,7 @@ class Password { return getAdditionValue(withKey: "Username") ?? getAdditionValue(withKey: "username") } - func getURL() -> String? { + func getURLString() -> String? { return getAdditionValue(withKey: "URL") ?? getAdditionValue(withKey: "url") ?? getAdditionValue(withKey: "Url") }