Skip to content

Commit

Permalink
Fix matching algorithm in AutoFill
Browse files Browse the repository at this point in the history
  • Loading branch information
mssun committed Jan 4, 2021
1 parent 9e8994f commit 571281b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
credentialProvider.identifier = serviceIdentifiers.first
let url = serviceIdentifiers.first.flatMap { URL(string: $0.identifier) }
passwordsViewController.navigationItem.prompt = url?.host
let keywords = url?.host?.sanitizedDomain?.components(separatedBy: ".") ?? []
passwordsViewController.showPasswordsWithSuggstion(keywords)
passwordsViewController.showPasswordsWithSuggstion(matching: url?.host ?? "")
}

override func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
Expand All @@ -57,7 +56,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
}
credentialProvider.identifier = credentialIdentity.serviceIdentifier
passwordsViewController.navigationItem.prompt = identifier
passwordsViewController.showPasswordsWithSuggstion([identifier])
passwordsViewController.showPasswordsWithSuggstion(matching: identifier)
}
}

Expand All @@ -68,14 +67,3 @@ extension CredentialProviderViewController: PasswordSelectionDelegate {
credentialProvider.persistAndProvideCredentials(with: passwordEntity.getPath())
}
}

private extension String {
var sanitizedDomain: String? {
replacingOccurrences(of: ".com", with: "")
.replacingOccurrences(of: ".org", with: "")
.replacingOccurrences(of: ".edu", with: "")
.replacingOccurrences(of: ".net", with: "")
.replacingOccurrences(of: ".gov", with: "")
.replacingOccurrences(of: "www.", with: "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class PasswordsViewController: UIViewController {
tableView.dataSource = dataSource
}

func showPasswordsWithSuggstion(_ keywords: [String]) {
dataSource.showTableEntriesWithSuggestion(matching: keywords)
func showPasswordsWithSuggstion(matching text: String) {
dataSource.showTableEntriesWithSuggestion(matching: text)
tableView.reloadData()
}

Expand Down
8 changes: 2 additions & 6 deletions passAutoFillExtension/Services/PasswordsTableDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,9 @@ class PasswordsTableDataSource: NSObject, UITableViewDataSource {
showSuggestion = false
}

func showTableEntriesWithSuggestion(matching keywords: [String]) {
func showTableEntriesWithSuggestion(matching text: String) {
for entry in passwordTableEntries {
var match = false
for keyword in keywords {
match = match || entry.match(keyword)
}
if match {
if entry.match(text) {
suggestedPasswordsTableEntries.append(entry)
} else {
otherPasswordsTableEntries.append(entry)
Expand Down

0 comments on commit 571281b

Please sign in to comment.