Skip to content

Support for experimental MSC4286 to not render external payment details #7927

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

Merged
merged 2 commits into from
May 28, 2025
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
10 changes: 10 additions & 0 deletions Riot/Modules/MatrixKit/Categories/DTHTMLElement+MatrixKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public extension DTHTMLElement {
// Remove any attachments to fix rendering.
textAttachment = nil

// Handle special case for span with data-mx-external-payment-details
// This could be based on Storefront.current.countryCode to show the link
// content in unrestricted countries. e.g. currently USA
if name == "span",
let attributes = attributes as? [String: String],
attributes["data-msc4286-external-payment-details"] != nil {
parent.removeChildNode(self)
return
}

// If the element has plain text content show that,
// otherwise prevent the tag from displaying.
if let stringContent = attributedString()?.string,
Expand Down
18 changes: 18 additions & 0 deletions RiotTests/MatrixKitTests/MXKEventFormatterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,24 @@ - (void)testRenderHTMLStringWithIFrame
XCTAssertFalse(hasAttachment, @"iFrame attachments should be removed as they're not included in the allowedHTMLTags array.");
}

- (void)testMxExternalPaymentDetailsRemoved
{
// Given an HTML string containing a <span> with data-mx-external-payment-details.
NSString *html = @"This is visible<span data-msc4286-external-payment-details>. But text is hidden <a href=\"https://matrix.org\">and this link too</a></span>";

// When rendering this string as an attributed string.
NSAttributedString *attributedString = [eventFormatter renderHTMLString:html
forEvent:anEvent
withRoomState:nil
andLatestRoomState:nil];

// Then the attributed string should have the <span> stripped and not include any attachments.
XCTAssertEqualObjects(attributedString.string, @"This is visible", @"The <span data-msc4286-external-payment-details> tag content should be removed.");

BOOL hasAttachment = [attributedString containsAttachmentsInRange:NSMakeRange(0, attributedString.length)];
XCTAssertFalse(hasAttachment, @"span attachments should be removed as they're not included in the allowedHTMLTags array.");
}

- (void)testRenderHTMLStringWithMXReply
{
// Given an HTML string representing a matrix reply.
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-7927.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support for experimental MSC4286 during event rendering.
Loading