Skip to content

Commit

Permalink
Fixes #2618 - Allow dashes in room identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Apr 2, 2024
1 parent 834a830 commit cb585ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ElementX/Sources/Other/MatrixEntityRegex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum MatrixEntityRegex: String {
case .roomAlias:
return "#[A-Z0-9._%#@=+-]+:" + MatrixEntityRegex.homeserver.rawValue
case .roomId:
return "![A-Z0-9]+:" + MatrixEntityRegex.homeserver.rawValue
return "![A-Z0-9_\\-\\/]+:" + MatrixEntityRegex.homeserver.rawValue
case .eventId:
return "\\$[a-z0-9_\\-\\/]+(:[a-z0-9]+\\.[a-z0-9]+)?"
case .allUsers:
Expand Down
1 change: 1 addition & 0 deletions UnitTests/Sources/MatrixEntityRegexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MatrixEntityRegexTests: XCTestCase {

func testRoomId() {
XCTAssertTrue(MatrixEntityRegex.isMatrixRoomIdentifier("!pMBteVpcoJRdCJxDmn:matrix.org"))
XCTAssertTrue(MatrixEntityRegex.isMatrixRoomIdentifier("!pMBte-Vpco-JRdCJxDmn:matrix.org"))
XCTAssertFalse(MatrixEntityRegex.isMatrixRoomIdentifier("pMBteVpcoJRdCJxDmn:matrix.org"))
XCTAssertFalse(MatrixEntityRegex.isMatrixRoomIdentifier("!pMBteVpcoJRdCJxDmn.matrix.org"))
}
Expand Down
11 changes: 11 additions & 0 deletions UnitTests/Sources/PermalinkBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ class PermalinkBuilderTests: XCTestCase {
}
}

func testMautrixBridgePermalink() throws {
let roomId = "!mautrix-signal-v6:maunium.net"

do {
let permalink = try PermalinkBuilder.permalinkTo(roomIdentifier: roomId, baseURL: appSettings.permalinkBaseURL)
XCTAssertEqual(permalink, URL(string: "\(appSettings.permalinkBaseURL)/#/!mautrix-signal-v6%3Amaunium.net"))
} catch {
XCTFail("Room identifier must be valid: \(error)")
}
}

func testInvalidRoomIdentifier() {
do {
_ = try PermalinkBuilder.permalinkTo(roomIdentifier: "This1sN0tV4lid!@#$%^&*()", baseURL: appSettings.permalinkBaseURL)
Expand Down
1 change: 1 addition & 0 deletions changelog.d/2618.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix room permalink building, allow dashes in room identifiers

0 comments on commit cb585ee

Please sign in to comment.