Skip to content

Commit

Permalink
Fixes /issues/6241 - Prevent random crashes when tapping links. Avoid…
Browse files Browse the repository at this point in the history
… displaying the confirmation alert for plain text ones.
  • Loading branch information
stefanceriu committed Jun 8, 2022
1 parent ceae4a4 commit 02d4007
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,12 @@ - (MXKRoomBubbleComponent*)closestBubbleComponentAtPosition:(CGPoint)position

NSArray *bubbleComponents = bubbleData.bubbleComponents;

if (bubbleComponents.count == 1) {
return bubbleComponents.firstObject;
}

// The position check below fails for bubble data with a single component when message
// bubbles are enabled, thus the early bailout above
for (MXKRoomBubbleComponent *component in bubbleComponents)
{
// Ignore components without display (For example redacted event or state events)
Expand Down
20 changes: 13 additions & 7 deletions Riot/Utils/URLValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions changelog.d/6241.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent random crashes when tapping links. Avoid displaying the confirmation alert for plain text ones.

0 comments on commit 02d4007

Please sign in to comment.