fix: Have matrix id string extension obay the proper grammar

This commit is contained in:
Sorunome 2020-08-11 17:27:11 +02:00 committed by Christian Pauly
parent 26586b6f02
commit 3d2476cfdb
2 changed files with 9 additions and 2 deletions

View file

@ -9,8 +9,14 @@ extension MatrixIdExtension on String {
if (!VALID_SIGILS.contains(substring(0, 1))) {
return false;
}
// event IDs do not have to have a domain
if (substring(0, 1) == '\$') {
return true;
}
// all other matrix IDs have to have a domain
final parts = substring(1).split(':');
if (parts.length != 2 || parts[0].isEmpty || parts[1].isEmpty) {
// the localpart can be an empty string, e.g. for aliases
if (parts.length != 2 || parts[1].isEmpty) {
return false;
}
return true;

View file

@ -29,9 +29,10 @@ void main() {
expect('!test:example.com'.isValidMatrixId, true);
expect('+test:example.com'.isValidMatrixId, true);
expect('\$test:example.com'.isValidMatrixId, true);
expect('\$testevent'.isValidMatrixId, true);
expect('test:example.com'.isValidMatrixId, false);
expect('@testexample.com'.isValidMatrixId, false);
expect('@:example.com'.isValidMatrixId, false);
expect('@:example.com'.isValidMatrixId, true);
expect('@test:'.isValidMatrixId, false);
expect(mxId.sigil, '@');
expect('#test:example.com'.sigil, '#');