From f8f858f15e4a433f90ba569e619ec16225d6dd1c Mon Sep 17 00:00:00 2001 From: Danny Moesch Date: Fri, 7 Dec 2018 21:55:30 +0100 Subject: [PATCH] Pass content of URL field to 'openLink' method Previously, 'openLink' has chosen the first URL field contained in the password file. Since the action "Copy & Open" is performed on a specific field, only its content should be considered. --- .../PasswordDetailTableViewController.swift | 21 +++++++++++-------- pass/Views/LabelTableViewCell.swift | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pass/Controllers/PasswordDetailTableViewController.swift b/pass/Controllers/PasswordDetailTableViewController.swift index 146f6a8..aba70c5 100644 --- a/pass/Controllers/PasswordDetailTableViewController.swift +++ b/pass/Controllers/PasswordDetailTableViewController.swift @@ -388,22 +388,25 @@ class PasswordDetailTableViewController: UITableViewController, UIGestureRecogni SVProgressHUD.dismiss(withDelay: 1) } } - - func openLink() { - var urlString = self.password?.urlString ?? "" - if !urlString.lowercased().starts(with: "https://") && !urlString.lowercased().starts(with: "http://") { - urlString = "http://\(urlString)" - } - guard let url = URL(string: urlString) else { - DispatchQueue.main.async { + + func openLink(to address: String?) { + guard address != nil, let url = URL(string: formActualWebAddress(from: address!)) else { + return DispatchQueue.main.async { Utils.alert(title: "Error", message: "Cannot find a valid URL", controller: self, completion: nil) } - return; } SecurePasteboard.shared.copy(textToCopy: password?.password) UIApplication.shared.open(url, options: [:], completionHandler: nil) } + private func formActualWebAddress(from: String) -> String { + let lowercased = from.lowercased() + if !(lowercased.starts(with: "https://") || lowercased.starts(with: "http://")) { + return "http://\(from)" + } + return from + } + override func numberOfSections(in tableView: UITableView) -> Int { return tableData.count } diff --git a/pass/Views/LabelTableViewCell.swift b/pass/Views/LabelTableViewCell.swift index 864834c..daa701b 100644 --- a/pass/Views/LabelTableViewCell.swift +++ b/pass/Views/LabelTableViewCell.swift @@ -141,7 +141,7 @@ class LabelTableViewCell: UITableViewCell { @objc func openLink(_ sender: Any?) { // if isURLCell, passwordTableView should not be nil - delegatePasswordTableView!.openLink() + delegatePasswordTableView!.openLink(to: cellData?.content) } @objc func getNextHOTP(_ sender: Any?) {