mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-30 21:26:57 +02:00
Fixes vector-im/element-ios/issues/6241 - Prevent random crashes when tapping links. Avoid displaying the confirmation alert for plain text ones.
This commit is contained in:
committed by
Stefan Ceriu
parent
2a208322f8
commit
ff0b0c370a
@@ -46,24 +46,30 @@ class URLValidator: NSObject {
|
||||
/// - event: Event containing the link
|
||||
/// - Returns: Validation result
|
||||
static func validateTappedURL(_ url: URL, in event: MXEvent) -> URLValidationResult {
|
||||
if let format = event.content["format"] as? String,
|
||||
let formattedBody = event.content["formatted_body"] as? String {
|
||||
guard let content = event.content else {
|
||||
return .passed
|
||||
}
|
||||
|
||||
if let format = content["format"] as? String,
|
||||
let formattedBody = content["formatted_body"] as? String {
|
||||
if format == kMXRoomMessageFormatHTML {
|
||||
let visibleURL = FormattedBodyParser().getVisibleURL(forURL: url, inFormattedBody: formattedBody)
|
||||
if url != visibleURL {
|
||||
if let visibleURL = FormattedBodyParser().getVisibleURL(forURL: url, inFormattedBody: formattedBody),
|
||||
url != visibleURL {
|
||||
// urls are different, show confirmation alert
|
||||
return .init(shouldShowConfirmationAlert: true,
|
||||
visibleURLString: visibleURL?.absoluteString)
|
||||
visibleURLString: visibleURL.absoluteString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let body = event.content[kMXMessageBodyKey] as? String,
|
||||
body.vc_containsRTLOverride(),
|
||||
body != url.absoluteString {
|
||||
body.vc_containsRTLOverride(),
|
||||
body != url.absoluteString {
|
||||
// we don't know where the url is in the body, assuming visibleString is just a reverse of the url
|
||||
return .init(shouldShowConfirmationAlert: true,
|
||||
visibleURLString: url.absoluteString.vc_reversed())
|
||||
}
|
||||
|
||||
return .passed
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user