Fixed throwing away everything after URL's path
This commit is contained in:
parent
8f7e2146ce
commit
2f321faa6a
|
@ -133,7 +133,7 @@ class FaviconFinder {
|
|||
|
||||
private func createFavicon(url: String?, siteUrl: String, iconType: FaviconType, sizesString: String?, type: String?) -> Favicon? {
|
||||
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 size = extractSizesFromString(sizesString)
|
||||
|
|
|
@ -114,4 +114,41 @@ extension 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)!
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue