diff --git a/packages/message-parser/src/grammar.pegjs b/packages/message-parser/src/grammar.pegjs index 7c636b6089..e76ebe0c72 100644 --- a/packages/message-parser/src/grammar.pegjs +++ b/packages/message-parser/src/grammar.pegjs @@ -177,15 +177,20 @@ anyText / [\x61-\x7A] // a b c d e f g h i j k l m n o p q r s t u v w x y z / nonascii -utf8_names_validation = $[0-9a-zA-Z-_.]+ +utf8_names_validation = $([-_.] / alphaChar / decimalNumberChar)+ -matrix_server_validation = ":" utf8_names_validation +username_matrix_server_validation = ":" utf8_names_validation + +username_email_validation = "@" utf8_names_validation UserMention = t:Text "@"+ user:utf8_names_validation { return reducePlainTexts([t, plain('@' + user)])[0]; } - / "@"+ user:$(utf8_names_validation matrix_server_validation) { + / "@"+ user:$(utf8_names_validation username_matrix_server_validation) { + return mentionUser(user); + } + / "@"+ user:$(utf8_names_validation username_email_validation) { return mentionUser(user); } / "@"+ user:utf8_names_validation { return mentionUser(user); } diff --git a/packages/message-parser/tests/mention.test.ts b/packages/message-parser/tests/mention.test.ts index a193393048..5a86d5587a 100644 --- a/packages/message-parser/tests/mention.test.ts +++ b/packages/message-parser/tests/mention.test.ts @@ -13,6 +13,22 @@ test.each([ '@marcos.defendi:matrix.org', [paragraph([mentionUser('marcos.defendi:matrix.org')])], ], + ['@username@example.com', [paragraph([mentionUser('username@example.com')])]], + [ + '@099fnd2ee@example.com', + [paragraph([mentionUser('099fnd2ee@example.com')])], + ], + ['@téstãçâò', [paragraph([mentionUser('téstãçâò')])]], + ['@สมชาย', [paragraph([mentionUser('สมชาย')])]], + ['@李祖阳', [paragraph([mentionUser('李祖阳')])]], + ['@あおい', [paragraph([mentionUser('あおい')])]], + ['@アオイ', [paragraph([mentionUser('アオイ')])]], + ['@Владимир', [paragraph([mentionUser('Владимир')])]], + ['@Кириллица', [paragraph([mentionUser('Кириллица')])]], + [ + 'test @Кириллица test', + [paragraph([plain('test '), mentionUser('Кириллица'), plain(' test')])], + ], ])('parses %p', (input, output) => { expect(parse(input)).toMatchObject(output); });