mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Regex: Fixes Permalink action on timeline (#303)
This commit is contained in:
@@ -31,14 +31,6 @@ extension String {
|
||||
|
||||
return string
|
||||
}
|
||||
|
||||
/// Whether or not the string is a Matrix user ID.
|
||||
var isMatrixUserID: Bool {
|
||||
let range = NSRange(location: 0, length: count)
|
||||
|
||||
let detector = try? NSRegularExpression(pattern: MatrixEntityRegex.userId.rawValue, options: .caseInsensitive)
|
||||
return detector?.numberOfMatches(in: self, range: range) ?? 0 == 1
|
||||
}
|
||||
|
||||
/// Calculates a numeric hash same as Element Web
|
||||
/// See original function here https://github.com/matrix-org/matrix-react-sdk/blob/321dd49db4fbe360fc2ff109ac117305c955b061/src/utils/FormattingUtils.js#L47
|
||||
|
||||
@@ -35,7 +35,7 @@ enum MatrixEntityRegex: String {
|
||||
case .roomId:
|
||||
return "![A-Z0-9]+:" + MatrixEntityRegex.homeserver.rawValue
|
||||
case .eventId:
|
||||
return "\\$[A-Z0-9\\/+]+"
|
||||
return "\\$[a-z0-9_\\-\\/]+(:[a-z0-9]+\\.[a-z0-9]+)?"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ enum MatrixEntityRegex: String {
|
||||
// swiftlint:enable force_try
|
||||
|
||||
static func isMatrixHomeserver(_ homeserver: String) -> Bool {
|
||||
guard let match = userIdentifierRegex.firstMatch(in: homeserver, range: .init(location: 0, length: homeserver.count)) else {
|
||||
guard let match = homeserverRegex.firstMatch(in: homeserver, range: .init(location: 0, length: homeserver.count)) else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ final class LoginCoordinator: Coordinator, Presentable {
|
||||
|
||||
/// Parses the specified username and looks up the homeserver when a Matrix ID is entered.
|
||||
private func parseUsername(_ username: String) {
|
||||
guard username.isMatrixUserID else { return }
|
||||
guard MatrixEntityRegex.isMatrixUserIdentifier(username) else { return }
|
||||
|
||||
let homeserverDomain = String(username.split(separator: ":")[1])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user