From 37f26ba0b04149ea56221361c6f4c9dff6f57372 Mon Sep 17 00:00:00 2001 From: chanhihi Date: Wed, 17 Apr 2024 00:05:13 +0900 Subject: [PATCH 1/5] fix: url decoding encoding --- iBox/Sources/Shared/AddBookmarkManager.swift | 28 +++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/iBox/Sources/Shared/AddBookmarkManager.swift b/iBox/Sources/Shared/AddBookmarkManager.swift index 68ce206..1b0962d 100644 --- a/iBox/Sources/Shared/AddBookmarkManager.swift +++ b/iBox/Sources/Shared/AddBookmarkManager.swift @@ -20,9 +20,9 @@ class AddBookmarkManager { private func update(with data: (title: String?, data: String?, faviconUrl: String?)) { DispatchQueue.main.async { - self.incomingTitle = data.title - self.incomingData = data.data - self.incomingFaviconUrl = data.faviconUrl + self.incomingTitle = data.title?.removingPercentEncoding + self.incomingData = data.data?.removingPercentEncoding + self.incomingFaviconUrl = data.faviconUrl?.removingPercentEncoding } } @@ -40,21 +40,31 @@ class AddBookmarkManager { } private func extractDataParameter(from url: URL) -> String? { - guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false), - let queryItems = components.queryItems else { + let urlString = url.absoluteString + + guard let range = urlString.range(of: "url?data=") else { return nil } - return queryItems.first { $0.name == "data" }?.value + + let dataParameter = urlString[range.upperBound...] + return String(dataParameter).removingPercentEncoding } private func fetchWebsiteDetails(from url: URL) { let task = URLSession.shared.dataTask(with: url) { [weak self] data, response, error in - guard let data = data, error == nil, - let html = String(data: data, encoding: .utf8) else { + guard let data = data, error == nil else { print("Error downloading HTML: \(String(describing: error))") return } + let encodingName = (response as? HTTPURLResponse)?.textEncodingName ?? "utf-8" + let encoding = String.Encoding(rawValue: CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding(encodingName as CFString))) + + guard let html = String(data: data, encoding: encoding) else { + print("Failed to decode data with encoding: \(encodingName)") + return + } + self?.parseHTML(html, url) } task.resume() @@ -63,7 +73,7 @@ class AddBookmarkManager { func navigateToAddBookmarkView(from url: URL, in tabBarController: UITabBarController) { guard url.scheme == "iBox", let urlString = extractDataParameter(from: url) else { return } guard let url = URL(string: urlString) else { - print("Invalid URL") + print("Invalid URL \(urlString)") return } From 041e207f869828501049d436be9f7da824ccadf5 Mon Sep 17 00:00:00 2001 From: chanhihi Date: Wed, 17 Apr 2024 00:05:37 +0900 Subject: [PATCH 2/5] fix: share extension encoding --- ShareExtension/Sources/ShareViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ShareExtension/Sources/ShareViewController.swift b/ShareExtension/Sources/ShareViewController.swift index a0678cd..f7493a6 100644 --- a/ShareExtension/Sources/ShareViewController.swift +++ b/ShareExtension/Sources/ShareViewController.swift @@ -133,7 +133,7 @@ extension CustomShareViewController: ShareExtensionBackGroundViewDelegate { return } - let urlString = "iBox://url?data=\(sharedURL)" + let urlString = "iBox://url?data=\(sharedURL)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" if let openUrl = URL(string: urlString) { if self.openURL(openUrl) { @@ -143,6 +143,7 @@ extension CustomShareViewController: ShareExtensionBackGroundViewDelegate { } } else { print("url error") + // 해당 url은 사용할 수 없음을 보여주는 뷰를 만들어야함. } } } From db1dcbec07a7efa6791f9fd2a389aeccddbd72b9 Mon Sep 17 00:00:00 2001 From: chanhihi Date: Wed, 17 Apr 2024 00:28:22 +0900 Subject: [PATCH 3/5] fix: url encoding in webviewdelegate --- iBox/Sources/Web/WebViewController.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iBox/Sources/Web/WebViewController.swift b/iBox/Sources/Web/WebViewController.swift index 5f017ea..e838341 100644 --- a/iBox/Sources/Web/WebViewController.swift +++ b/iBox/Sources/Web/WebViewController.swift @@ -46,9 +46,11 @@ class WebViewController: BaseViewController, BaseViewControllerProtocol extension WebViewController: WebViewDelegate { func pushAddBookMarkViewController(url: URL) { - AddBookmarkManager.shared.incomingData = url.absoluteString + let encodingURL = url.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" - if let iBoxUrl = URL(string: "iBox://url?data=" + url.absoluteString) { + AddBookmarkManager.shared.incomingData = encodingURL + + if let iBoxUrl = URL(string: "iBox://url?data=" + encodingURL) { if let tabBarController = findMainTabBarController() { AddBookmarkManager.shared.navigateToAddBookmarkView(from: iBoxUrl, in: tabBarController) } From 24fd632584a42e37d7412f12ade056523862c36c Mon Sep 17 00:00:00 2001 From: chanhihi Date: Wed, 17 Apr 2024 00:35:53 +0900 Subject: [PATCH 4/5] fix: delete incomingData --- iBox/Sources/Web/WebViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iBox/Sources/Web/WebViewController.swift b/iBox/Sources/Web/WebViewController.swift index e838341..d129f79 100644 --- a/iBox/Sources/Web/WebViewController.swift +++ b/iBox/Sources/Web/WebViewController.swift @@ -48,7 +48,7 @@ extension WebViewController: WebViewDelegate { func pushAddBookMarkViewController(url: URL) { let encodingURL = url.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" - AddBookmarkManager.shared.incomingData = encodingURL +// AddBookmarkManager.shared.incomingData = encodingURL if let iBoxUrl = URL(string: "iBox://url?data=" + encodingURL) { if let tabBarController = findMainTabBarController() { From 41e90899756b74ab6cdcb3c172b994e21e4321b8 Mon Sep 17 00:00:00 2001 From: jonnwon Date: Wed, 17 Apr 2024 00:42:44 +0900 Subject: [PATCH 5/5] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iBox/Sources/Web/WebViewController.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/iBox/Sources/Web/WebViewController.swift b/iBox/Sources/Web/WebViewController.swift index d129f79..4c09737 100644 --- a/iBox/Sources/Web/WebViewController.swift +++ b/iBox/Sources/Web/WebViewController.swift @@ -48,8 +48,6 @@ extension WebViewController: WebViewDelegate { func pushAddBookMarkViewController(url: URL) { let encodingURL = url.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "" -// AddBookmarkManager.shared.incomingData = encodingURL - if let iBoxUrl = URL(string: "iBox://url?data=" + encodingURL) { if let tabBarController = findMainTabBarController() { AddBookmarkManager.shared.navigateToAddBookmarkView(from: iBoxUrl, in: tabBarController)