Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit 7876ffe

Browse files
authored
Merge pull request #3800 from dan-weaver/bug/mention-regex
fixed mention regex to respect dots in usernames
2 parents b8d2798 + b81cd7e commit 7876ffe

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

shared/clients/draft-js/mentions-decorator/test/mentions-decorator.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ describe('strategy', () => {
5555
expect(mentions[1]).toEqual('@brian');
5656
});
5757

58+
it('should allow special characters', () => {
59+
const text = "Hey I'm @john-doe, I also go by @john_doe or @john.doe";
60+
const mentions = getMentions(text);
61+
expect(mentions).toEqual(['@john-doe', '@john_doe', '@john.doe']);
62+
});
63+
5864
describe('edge cases', () => {
5965
it('should handle sentences with compound emojis (withspectrum/spectrum#2077)', () => {
6066
const text =
@@ -63,5 +69,17 @@ describe('strategy', () => {
6369
expect(mentions[0]).toEqual('@grdp');
6470
expect(mentions[1]).toEqual('@rauchg');
6571
});
72+
it('should not include trailing period', () => {
73+
const text =
74+
"Hey guys it's @abc.123. where is @xyz? Any news from that guy? @abc.123... over and out. cc: @some.other.person- @ceo; @hr,.";
75+
76+
const mentions = getMentions(text);
77+
expect(mentions[0]).toEqual('@abc.123');
78+
expect(mentions[1]).toEqual('@xyz');
79+
expect(mentions[2]).toEqual('@abc.123');
80+
expect(mentions[3]).toEqual('@some.other.person-');
81+
expect(mentions[4]).toEqual('@ceo');
82+
expect(mentions[5]).toEqual('@hr');
83+
});
6684
});
6785
});

shared/regexps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
22

3-
module.exports.MENTIONS = /\/?\B@[a-z0-9_-]+/gi;
3+
module.exports.MENTIONS = /\/?\B@[a-z0-9._-]+[a-z0-9_-]/gi;
44
module.exports.URL = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*)/gi;
55
module.exports.RELATIVE_URL = /^\/([^\/].*|$)/g;

0 commit comments

Comments
 (0)