Fix inline completion showing "news." instead of "news.ycombinator.com"
Reject URLs whose host lacks a TLD (no internal dot) from autocompletion candidates, history recording, and clean up existing bogus entries on load.
This commit is contained in:
parent
7d290a1c24
commit
de6cfededa
2 changed files with 1579 additions and 258 deletions
|
|
@ -184,6 +184,18 @@ final class BrowserHistoryStore: ObservableObject {
|
|||
|
||||
// Most-recent first.
|
||||
entries = decoded.sorted(by: { $0.lastVisited > $1.lastVisited })
|
||||
|
||||
// Remove entries with invalid hosts (no TLD), e.g. "https://news."
|
||||
let beforeCount = entries.count
|
||||
entries.removeAll { entry in
|
||||
guard let url = URL(string: entry.url),
|
||||
let host = url.host?.lowercased() else { return false }
|
||||
let trimmed = host.hasSuffix(".") ? String(host.dropLast()) : host
|
||||
return !trimmed.contains(".")
|
||||
}
|
||||
if entries.count != beforeCount {
|
||||
scheduleSave()
|
||||
}
|
||||
}
|
||||
|
||||
func recordVisit(url: URL?, title: String?) {
|
||||
|
|
@ -192,6 +204,11 @@ final class BrowserHistoryStore: ObservableObject {
|
|||
guard let url else { return }
|
||||
guard let scheme = url.scheme?.lowercased(),
|
||||
scheme == "http" || scheme == "https" else { return }
|
||||
// Skip URLs whose host lacks a TLD (e.g. "https://news.").
|
||||
if let host = url.host?.lowercased() {
|
||||
let trimmed = host.hasSuffix(".") ? String(host.dropLast()) : host
|
||||
if !trimmed.contains(".") { return }
|
||||
}
|
||||
|
||||
let urlString = url.absoluteString
|
||||
guard urlString != "about:blank" else { return }
|
||||
|
|
@ -232,6 +249,11 @@ final class BrowserHistoryStore: ObservableObject {
|
|||
guard let url else { return }
|
||||
guard let scheme = url.scheme?.lowercased(),
|
||||
scheme == "http" || scheme == "https" else { return }
|
||||
// Skip URLs whose host lacks a TLD (e.g. "https://news.").
|
||||
if let host = url.host?.lowercased() {
|
||||
let trimmed = host.hasSuffix(".") ? String(host.dropLast()) : host
|
||||
if !trimmed.contains(".") { return }
|
||||
}
|
||||
|
||||
let urlString = url.absoluteString
|
||||
guard urlString != "about:blank" else { return }
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue