mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-11 13:59:13 +00:00
Remove now unused room and event matrix entity regexes
This commit is contained in:
parent
fcc25dd441
commit
891315ef04
@ -15,14 +15,12 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
// https://spec.matrix.org/latest/appendices/#identifier-grammar
|
||||
enum MatrixEntityRegex: String {
|
||||
case homeserver
|
||||
case userId
|
||||
case roomAlias
|
||||
case roomId
|
||||
case eventId
|
||||
case allUsers
|
||||
|
||||
var rawValue: String {
|
||||
@ -31,12 +29,6 @@ enum MatrixEntityRegex: String {
|
||||
return "[A-Z0-9]+((\\.|\\-)[A-Z0-9]+){0,}(:[0-9]{2,5})?"
|
||||
case .userId:
|
||||
return "@[\\x21-\\x39\\x3B-\\x7F]+:" + MatrixEntityRegex.homeserver.rawValue
|
||||
case .roomAlias:
|
||||
return "#[A-Z0-9._%#@=+-]+:" + MatrixEntityRegex.homeserver.rawValue
|
||||
case .roomId:
|
||||
return "![A-Z0-9_\\-\\/]+:" + MatrixEntityRegex.homeserver.rawValue
|
||||
case .eventId:
|
||||
return "\\$[a-z0-9_\\-\\/]+(:[a-z0-9]+\\.[a-z0-9]+)?"
|
||||
case .allUsers:
|
||||
return PillConstants.atRoom
|
||||
}
|
||||
@ -45,9 +37,6 @@ enum MatrixEntityRegex: String {
|
||||
// swiftlint:disable force_try
|
||||
static var homeserverRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.homeserver.rawValue, options: .caseInsensitive)
|
||||
static var userIdentifierRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.userId.rawValue, options: .caseInsensitive)
|
||||
static var roomAliasRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.roomAlias.rawValue, options: .caseInsensitive)
|
||||
static var roomIdentifierRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.roomId.rawValue, options: .caseInsensitive)
|
||||
static var eventIdentifierRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.eventId.rawValue, options: .caseInsensitive)
|
||||
static var allUsersRegex = try! NSRegularExpression(pattern: MatrixEntityRegex.allUsers.rawValue)
|
||||
static var linkRegex = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
|
||||
// swiftlint:enable force_try
|
||||
@ -68,30 +57,6 @@ enum MatrixEntityRegex: String {
|
||||
return match.range.length == identifier.count
|
||||
}
|
||||
|
||||
static func isMatrixRoomAlias(_ alias: String) -> Bool {
|
||||
guard let match = roomAliasRegex.firstMatch(in: alias) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return match.range.length == alias.count
|
||||
}
|
||||
|
||||
static func isMatrixRoomIdentifier(_ identifier: String) -> Bool {
|
||||
guard let match = roomIdentifierRegex.firstMatch(in: identifier) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return match.range.length == identifier.count
|
||||
}
|
||||
|
||||
static func isMatrixEventIdentifier(_ identifier: String) -> Bool {
|
||||
guard let match = eventIdentifierRegex.firstMatch(in: identifier) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return match.range.length == identifier.count
|
||||
}
|
||||
|
||||
static func containsMatrixAllUsers(_ string: String) -> Bool {
|
||||
guard allUsersRegex.firstMatch(in: string) != nil else {
|
||||
return false
|
||||
|
@ -32,39 +32,6 @@ class MatrixEntityRegexTests: XCTestCase {
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixUserIdentifier("username:example.com"))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixUserIdentifier("@username.example.com"))
|
||||
}
|
||||
|
||||
func testRoomAlias() {
|
||||
XCTAssertTrue(MatrixEntityRegex.isMatrixRoomAlias("#element-ios:matrix.org"))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixRoomAlias("element-ios:matrix.org"))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixRoomAlias("#element-ios.matrix.org"))
|
||||
}
|
||||
|
||||
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"))
|
||||
}
|
||||
|
||||
func testEventId() {
|
||||
// room version 1
|
||||
XCTAssertTrue(MatrixEntityRegex.isMatrixEventIdentifier("$h29iv0s8:example.com"))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixEventIdentifier("$h29iv0s8:example."))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixEventIdentifier("$h29iv0s8:"))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixEventIdentifier("$h29iv0s8?"))
|
||||
|
||||
// room version 3
|
||||
XCTAssertTrue(MatrixEntityRegex.isMatrixEventIdentifier("$acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk"))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixEventIdentifier("$acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk."))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixEventIdentifier("$acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk:"))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixEventIdentifier("$acR1l0raoZnm60CBwAVgqbZqoO/mYU81xysh1u7XcJk?"))
|
||||
|
||||
// room version 4
|
||||
XCTAssertTrue(MatrixEntityRegex.isMatrixEventIdentifier("$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg"))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixEventIdentifier("$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg."))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixEventIdentifier("$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg:"))
|
||||
XCTAssertFalse(MatrixEntityRegex.isMatrixEventIdentifier("$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg?"))
|
||||
}
|
||||
|
||||
func testAllUsers() {
|
||||
XCTAssertTrue(MatrixEntityRegex.containsMatrixAllUsers("@room"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user