Skip to content

Commit 571281b

Browse files
committed
Fix matching algorithm in AutoFill
1 parent 9e8994f commit 571281b

File tree

3 files changed

+6
-22
lines changed

3 files changed

+6
-22
lines changed

passAutoFillExtension/Controllers/CredentialProviderViewController.swift

+2-14
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
3838
credentialProvider.identifier = serviceIdentifiers.first
3939
let url = serviceIdentifiers.first.flatMap { URL(string: $0.identifier) }
4040
passwordsViewController.navigationItem.prompt = url?.host
41-
let keywords = url?.host?.sanitizedDomain?.components(separatedBy: ".") ?? []
42-
passwordsViewController.showPasswordsWithSuggstion(keywords)
41+
passwordsViewController.showPasswordsWithSuggstion(matching: url?.host ?? "")
4342
}
4443

4544
override func provideCredentialWithoutUserInteraction(for credentialIdentity: ASPasswordCredentialIdentity) {
@@ -57,7 +56,7 @@ class CredentialProviderViewController: ASCredentialProviderViewController {
5756
}
5857
credentialProvider.identifier = credentialIdentity.serviceIdentifier
5958
passwordsViewController.navigationItem.prompt = identifier
60-
passwordsViewController.showPasswordsWithSuggstion([identifier])
59+
passwordsViewController.showPasswordsWithSuggstion(matching: identifier)
6160
}
6261
}
6362

@@ -68,14 +67,3 @@ extension CredentialProviderViewController: PasswordSelectionDelegate {
6867
credentialProvider.persistAndProvideCredentials(with: passwordEntity.getPath())
6968
}
7069
}
71-
72-
private extension String {
73-
var sanitizedDomain: String? {
74-
replacingOccurrences(of: ".com", with: "")
75-
.replacingOccurrences(of: ".org", with: "")
76-
.replacingOccurrences(of: ".edu", with: "")
77-
.replacingOccurrences(of: ".net", with: "")
78-
.replacingOccurrences(of: ".gov", with: "")
79-
.replacingOccurrences(of: "www.", with: "")
80-
}
81-
}

passAutoFillExtension/Controllers/PasswordsViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class PasswordsViewController: UIViewController {
4343
tableView.dataSource = dataSource
4444
}
4545

46-
func showPasswordsWithSuggstion(_ keywords: [String]) {
47-
dataSource.showTableEntriesWithSuggestion(matching: keywords)
46+
func showPasswordsWithSuggstion(matching text: String) {
47+
dataSource.showTableEntriesWithSuggestion(matching: text)
4848
tableView.reloadData()
4949
}
5050

passAutoFillExtension/Services/PasswordsTableDataSource.swift

+2-6
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,9 @@ class PasswordsTableDataSource: NSObject, UITableViewDataSource {
9191
showSuggestion = false
9292
}
9393

94-
func showTableEntriesWithSuggestion(matching keywords: [String]) {
94+
func showTableEntriesWithSuggestion(matching text: String) {
9595
for entry in passwordTableEntries {
96-
var match = false
97-
for keyword in keywords {
98-
match = match || entry.match(keyword)
99-
}
100-
if match {
96+
if entry.match(text) {
10197
suggestedPasswordsTableEntries.append(entry)
10298
} else {
10399
otherPasswordsTableEntries.append(entry)

0 commit comments

Comments
 (0)