Skip to content

Commit aa9bc06

Browse files
fix(message-parser): User mention with @ character (#894)
* Fix user mention with email pattern and add tests * adding languages support to mention and channel parser Co-authored-by: gabriellsh <40830821+gabriellsh@users.noreply.github.com>
1 parent 25419be commit aa9bc06

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

packages/message-parser/src/grammar.pegjs

+8-3
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,20 @@ anyText
177177
/ [\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
178178
/ nonascii
179179

180-
utf8_names_validation = $[0-9a-zA-Z-_.]+
180+
utf8_names_validation = $([-_.] / alphaChar / decimalNumberChar)+
181181

182-
matrix_server_validation = ":" utf8_names_validation
182+
username_matrix_server_validation = ":" utf8_names_validation
183+
184+
username_email_validation = "@" utf8_names_validation
183185

184186
UserMention
185187
= t:Text "@"+ user:utf8_names_validation {
186188
return reducePlainTexts([t, plain('@' + user)])[0];
187189
}
188-
/ "@"+ user:$(utf8_names_validation matrix_server_validation) {
190+
/ "@"+ user:$(utf8_names_validation username_matrix_server_validation) {
191+
return mentionUser(user);
192+
}
193+
/ "@"+ user:$(utf8_names_validation username_email_validation) {
189194
return mentionUser(user);
190195
}
191196
/ "@"+ user:utf8_names_validation { return mentionUser(user); }

packages/message-parser/tests/mention.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ test.each([
1313
'@marcos.defendi:matrix.org',
1414
[paragraph([mentionUser('marcos.defendi:matrix.org')])],
1515
],
16+
['@username@example.com', [paragraph([mentionUser('username@example.com')])]],
17+
[
18+
'@099fnd2ee@example.com',
19+
[paragraph([mentionUser('099fnd2ee@example.com')])],
20+
],
21+
['@téstãçâò', [paragraph([mentionUser('téstãçâò')])]],
22+
['@สมชาย', [paragraph([mentionUser('สมชาย')])]],
23+
['@李祖阳', [paragraph([mentionUser('李祖阳')])]],
24+
['@あおい', [paragraph([mentionUser('あおい')])]],
25+
['@アオイ', [paragraph([mentionUser('アオイ')])]],
26+
['@Владимир', [paragraph([mentionUser('Владимир')])]],
27+
['@Кириллица', [paragraph([mentionUser('Кириллица')])]],
28+
[
29+
'test @Кириллица test',
30+
[paragraph([plain('test '), mentionUser('Кириллица'), plain(' test')])],
31+
],
1632
])('parses %p', (input, output) => {
1733
expect(parse(input)).toMatchObject(output);
1834
});

0 commit comments

Comments
 (0)