Normalize homePageURL in FaviconDownloader — this avoids doing duplicate work for http://foo.com/ and http://foo.com — they’re both treated as http://foo.com/
This commit is contained in:
parent
61c429d45c
commit
ba638ecda1
@ -61,7 +61,7 @@ final class FaviconDownloader {
|
|||||||
|
|
||||||
func favicon(withHomePageURL homePageURL: String) -> NSImage? {
|
func favicon(withHomePageURL homePageURL: String) -> NSImage? {
|
||||||
|
|
||||||
guard let seekingFavicon = seekingFavicon(with: homePageURL) else {
|
guard let seekingFavicon = seekingFavicon(with: normalizedHomePageURL(homePageURL)) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return favicon(withSeekingFavicon: seekingFavicon)
|
return favicon(withSeekingFavicon: seekingFavicon)
|
||||||
@ -92,6 +92,26 @@ final class FaviconDownloader {
|
|||||||
|
|
||||||
private extension FaviconDownloader {
|
private extension FaviconDownloader {
|
||||||
|
|
||||||
|
private static let localeForLowercasing = Locale(identifier: "en_US")
|
||||||
|
|
||||||
|
func normalizedHomePageURL(_ url: String) -> String {
|
||||||
|
|
||||||
|
// Many times the homePageURL is missing a trailing /.
|
||||||
|
// We add one when needed.
|
||||||
|
|
||||||
|
guard !url.hasSuffix("/") else {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
let lowercasedURL = url.lowercased(with: FaviconDownloader.localeForLowercasing)
|
||||||
|
guard lowercasedURL.hasPrefix("http://") || lowercasedURL.hasPrefix("https://") else {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
guard url.components(separatedBy: "/").count < 4 else {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
return url + "/"
|
||||||
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
func favicon(withSeekingFavicon seekingFavicon: SeekingFavicon) -> NSImage? {
|
func favicon(withSeekingFavicon seekingFavicon: SeekingFavicon) -> NSImage? {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user