Fixed throwing away everything after URL's path

This commit is contained in:
dankito 2020-08-03 22:01:16 +02:00
parent 8f7e2146ce
commit 2f321faa6a
2 changed files with 38 additions and 1 deletions

View File

@ -133,7 +133,7 @@ class FaviconFinder {
private func createFavicon(url: String?, siteUrl: String, iconType: FaviconType, sizesString: String?, type: String?) -> Favicon? { private func createFavicon(url: String?, siteUrl: String, iconType: FaviconType, sizesString: String?, type: String?) -> Favicon? {
if let url = url { if let url = url {
let urlWithoutQuery = URL(string: url)?.path ?? url // TODO: find a better solution to remove query / fragment let urlWithoutQuery = URL(string: url)?.absoluteStringWithouthQueryAndFragment ?? url
let absoluteUrl = makeLinkAbsolute(url: urlWithoutQuery, siteUrl: siteUrl) let absoluteUrl = makeLinkAbsolute(url: urlWithoutQuery, siteUrl: siteUrl)
let size = extractSizesFromString(sizesString) let size = extractSizesFromString(sizesString)

View File

@ -114,4 +114,41 @@ extension URL {
return URL(string: url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? url) return URL(string: url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? url)
} }
var absoluteStringWithouthQuery: String {
let absoluteString = self.absoluteString
let indexOfQuestionMark = absoluteString.firstIndex(of: "?")
if let index = indexOfQuestionMark {
return String(absoluteString[..<index])
}
return absoluteString
}
var absoluteStringWithouthFragment: String {
return absoluteStringWithouthFragment(self.absoluteString)
}
private func absoluteStringWithouthFragment(_ absoluteString: String) -> String {
let indexOfHash = absoluteString.firstIndex(of: "#")
if let index = indexOfHash {
return String(absoluteString[..<index])
}
return absoluteString
}
var absoluteStringWithouthQueryAndFragment: String {
let absoluteStringWithouthQuery = self.absoluteStringWithouthQuery
return absoluteStringWithouthFragment(absoluteStringWithouthQuery)
}
var removeQueryAndFragment: URL {
return URL(string: self.absoluteStringWithouthQueryAndFragment)!
}
} }