From 2f321faa6afaa5e3e701a850efa1085098d46047 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 3 Aug 2020 22:01:16 +0200 Subject: [PATCH] Fixed throwing away everything after URL's path --- .../BankIconFinder/FaviconFinder.swift | 2 +- .../BankingiOSApp/ui/SwiftExtensions.swift | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/BankIconFinder/FaviconFinder.swift b/ui/BankingiOSApp/BankingiOSApp/BankIconFinder/FaviconFinder.swift index 033a6a86..8b4c6882 100644 --- a/ui/BankingiOSApp/BankingiOSApp/BankIconFinder/FaviconFinder.swift +++ b/ui/BankingiOSApp/BankingiOSApp/BankIconFinder/FaviconFinder.swift @@ -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) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift b/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift index 3fa81ad0..374cff98 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift @@ -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[.. String { + let indexOfHash = absoluteString.firstIndex(of: "#") + + if let index = indexOfHash { + return String(absoluteString[..