Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-2632 DeepLinks | Add parsing for html symbols in links #1165

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ struct ErrorStateView: View {

var body: some View {
VStack(spacing: 0) {
Spacer()
ButtomAlertHeaderImageView(icon: .BottomAlert.error, style: .color(.red))
Spacer.fixedHeight(12)
AnytypeText(Loc.error, style: .uxCalloutMedium)
Expand All @@ -14,9 +13,9 @@ struct ErrorStateView: View {
AnytypeText(message, style: .uxCalloutRegular)
.foregroundColor(.Text.primary)
.multilineTextAlignment(.center)
Spacer()
}
.padding(.horizontal, 20)
.padding(.vertical, 12)
}
}

Expand Down
3 changes: 2 additions & 1 deletion Modules/DeepLinks/Sources/DeepLinks/DeepLinkParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ final class DeepLinkParser: DeepLinkParserProtocol {
}

public func parse(url: URL) -> DeepLink? {
guard var components = URLComponents(url: url, resolvingAgainstBaseURL: false) else { return nil }
let urlString = url.absoluteString.replacingHTMLEntities
guard var components = URLComponents(string: urlString) else { return nil }

let queryItems = components.queryItems ?? []
components.queryItems = nil
Expand Down
24 changes: 24 additions & 0 deletions Modules/DeepLinks/Sources/DeepLinks/String+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Foundation
import UIKit

extension String {
var replacingHTMLEntities: String {
guard let data = data(using: .utf8) else { return self }
do {
// Some links can contains html entities.
// For example, wher user tap link in slack, it is replace & to & .
// Uses WebKit for parsing text and replace html entities to normal symbols.
let attributedString = try NSAttributedString(
data: data,
options: [
.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue
],
documentAttributes: nil
)
return attributedString.string
} catch {
return self
}
}
}
Loading