Skip to content

Commit

Permalink
MXTools: Update isMatrixEventIdentifier to support room v3 event ids
Browse files Browse the repository at this point in the history
  • Loading branch information
manuroe committed Feb 13, 2019
1 parent 6e21500 commit 454a3fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion MatrixSDK/Utils/MXTools.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
NSString *const kMXToolsRegexStringForMatrixRoomAlias = @"#[A-Z0-9._%#@+-]+:" MATRIX_HOMESERVER_DOMAIN_REGEX; NSString *const kMXToolsRegexStringForMatrixRoomAlias = @"#[A-Z0-9._%#@+-]+:" MATRIX_HOMESERVER_DOMAIN_REGEX;
NSString *const kMXToolsRegexStringForMatrixRoomIdentifier = @"![A-Z0-9]+:" MATRIX_HOMESERVER_DOMAIN_REGEX; NSString *const kMXToolsRegexStringForMatrixRoomIdentifier = @"![A-Z0-9]+:" MATRIX_HOMESERVER_DOMAIN_REGEX;
NSString *const kMXToolsRegexStringForMatrixEventIdentifier = @"\\$[A-Z0-9]+:" MATRIX_HOMESERVER_DOMAIN_REGEX; NSString *const kMXToolsRegexStringForMatrixEventIdentifier = @"\\$[A-Z0-9]+:" MATRIX_HOMESERVER_DOMAIN_REGEX;
NSString *const kMXToolsRegexStringForMatrixEventIdentifierV3 = @"\\$[A-Z0-9\\/+]+";
NSString *const kMXToolsRegexStringForMatrixGroupIdentifier = @"\\+[A-Z0-9=_\\-./]+:" MATRIX_HOMESERVER_DOMAIN_REGEX; NSString *const kMXToolsRegexStringForMatrixGroupIdentifier = @"\\+[A-Z0-9=_\\-./]+:" MATRIX_HOMESERVER_DOMAIN_REGEX;




Expand All @@ -45,6 +46,7 @@
static NSRegularExpression *isMatrixRoomAliasRegex; static NSRegularExpression *isMatrixRoomAliasRegex;
static NSRegularExpression *isMatrixRoomIdentifierRegex; static NSRegularExpression *isMatrixRoomIdentifierRegex;
static NSRegularExpression *isMatrixEventIdentifierRegex; static NSRegularExpression *isMatrixEventIdentifierRegex;
static NSRegularExpression *isMatrixEventIdentifierV3Regex;
static NSRegularExpression *isMatrixGroupIdentifierRegex; static NSRegularExpression *isMatrixGroupIdentifierRegex;


// A regex to find new lines // A regex to find new lines
Expand Down Expand Up @@ -117,6 +119,9 @@ + (void)initialize
options:NSRegularExpressionCaseInsensitive error:nil]; options:NSRegularExpressionCaseInsensitive error:nil];
isMatrixEventIdentifierRegex = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"^%@$", kMXToolsRegexStringForMatrixEventIdentifier] isMatrixEventIdentifierRegex = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"^%@$", kMXToolsRegexStringForMatrixEventIdentifier]
options:NSRegularExpressionCaseInsensitive error:nil]; options:NSRegularExpressionCaseInsensitive error:nil];
isMatrixEventIdentifierV3Regex = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"^%@$", kMXToolsRegexStringForMatrixEventIdentifierV3]
options:NSRegularExpressionCaseInsensitive error:nil];

isMatrixGroupIdentifierRegex = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"^%@$", kMXToolsRegexStringForMatrixGroupIdentifier] isMatrixGroupIdentifierRegex = [NSRegularExpression regularExpressionWithPattern:[NSString stringWithFormat:@"^%@$", kMXToolsRegexStringForMatrixGroupIdentifier]
options:NSRegularExpressionCaseInsensitive error:nil]; options:NSRegularExpressionCaseInsensitive error:nil];


Expand Down Expand Up @@ -337,7 +342,8 @@ + (BOOL)isMatrixEventIdentifier:(NSString *)inputString
{ {
if (inputString) if (inputString)
{ {
return (nil != [isMatrixEventIdentifierRegex firstMatchInString:inputString options:0 range:NSMakeRange(0, inputString.length)]); return (nil != [isMatrixEventIdentifierRegex firstMatchInString:inputString options:0 range:NSMakeRange(0, inputString.length)])
|| (nil != [isMatrixEventIdentifierV3Regex firstMatchInString:inputString options:0 range:NSMakeRange(0, inputString.length)]);
} }
return NO; return NO;
} }
Expand Down
1 change: 1 addition & 0 deletions MatrixSDKTests/MXToolsTests.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ - (void)testMatrixIdentifiers
XCTAssertTrue([MXTools isMatrixUserIdentifier:@"@+33012:matrix.org"]); XCTAssertTrue([MXTools isMatrixUserIdentifier:@"@+33012:matrix.org"]);


XCTAssertTrue([MXTools isMatrixEventIdentifier:@"$123456EventId:matrix.org"]); XCTAssertTrue([MXTools isMatrixEventIdentifier:@"$123456EventId:matrix.org"]);
XCTAssertTrue([MXTools isMatrixEventIdentifier:@"$pmOSN/DognfuSfhdW/qivXT19lfCWpdSfaPFKDBTJUk+"]);


XCTAssertTrue([MXTools isMatrixRoomIdentifier:@"!an1234Room:matrix.org"]); XCTAssertTrue([MXTools isMatrixRoomIdentifier:@"!an1234Room:matrix.org"]);


Expand Down

0 comments on commit 454a3fc

Please sign in to comment.