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.
This commit is contained in:
Danny Moesch 2018-12-07 21:55:30 +01:00 committed by Bob Sun
parent 9b7fc4219e
commit f8f858f15e
2 changed files with 13 additions and 10 deletions

View file

@ -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
}

View file

@ -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?) {