Skip to content

Commit

Permalink
Merge pull request #594 from agilejune/fix-#21753
Browse files Browse the repository at this point in the history
fix the issue that inconsistent highlighting occurs when multiple mentions are used without spaces
  • Loading branch information
puneetlath committed Nov 19, 2023
2 parents 7c72af4 + bdbef09 commit d24d6fa
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
46 changes: 46 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,52 @@ test('Test for @here mention without space or supported styling character', () =
expect(parser.replace(testString)).toBe(resultString);
});

test('Test user mention and here mention, which are concatenated without space', () => {
let testString = '@[email protected]@here';
let resultString = '<mention-user>@[email protected]</mention-user><mention-here>@here</mention-here>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected][email protected]';
resultString = '<mention-here>@here</mention-here><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected]@[email protected]';
resultString = '<mention-user>@[email protected]</mention-user><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@here@[email protected]';
resultString = '<mention-here>@here</mention-here><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected]@here';
resultString = '<mention-user>@[email protected]</mention-user><mention-here>@here</mention-here>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@here@[email protected]';
resultString = '<mention-here>@here</mention-here><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected]@here';
resultString = '<mention-user>@[email protected]</mention-user><mention-here>@here</mention-here>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected]@here@[email protected]';
resultString = '<mention-user>@[email protected]</mention-user><mention-here>@here</mention-here><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected]@here@[email protected]';
resultString = '<mention-user>@[email protected]</mention-user><mention-here>@here</mention-here><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected]@here@[email protected]';
resultString = '<mention-user>@[email protected]</mention-user><mention-here>@here</mention-here><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);

testString = '@[email protected]@here@here@[email protected]@here@[email protected]';
resultString = '<mention-user>@[email protected]</mention-user><mention-here>@here</mention-here><mention-here>@here</mention-here><mention-user>@[email protected]</mention-user><mention-here>@here</mention-here><mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for mention inside link and email markdown', () => {
const testString = '[@[email protected]](expensify.com) '
+ '[_@[email protected]_](expensify.com) '
Expand Down
14 changes: 10 additions & 4 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class ExpensiMark {
*/
{
name: 'hereMentions',
regex: /([a-zA-Z0-9.!$%&+/=?^`{|}_-]?)(@here)([.!$%&+/=?^`{|}_-]?)(?=\b)(?!(@[a-zA-Z0-9-]+?(\.[a-zA-Z]+)+)|((?:(?!<a).)+)?<\/a>|[^<]*(<\/pre>|<\/code>))/gm,
regex: /([a-zA-Z0-9.!$%&+/=?^`{|}_-]?)(@here)([.!$%&+/=?^`{|}_-]?)(?=\b)(?!([\w'#%+-]*@(?:[a-z\d-]+\.)+[a-z]{2,}(?:\s|$|@here))|((?:(?!<a).)+)?<\/a>|[^<]*(<\/pre>|<\/code>))/gm,
replacement: (match, g1, g2, g3) => {
if (!Str.isValidMention(match)) {
return match;
Expand All @@ -121,15 +121,21 @@ export default class ExpensiMark {
*/
{
name: 'userMentions',
regex: new RegExp(`[a-zA-Z0-9.!$%&+/=?^\`{|}-]?@+${CONST.REG_EXP.EMAIL_PART}(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>))`, 'gmi'),
replacement: (match) => {
regex: new RegExp(`(@here|[a-zA-Z0-9.!$%&+=?^\`{|}-]?)(@+${CONST.REG_EXP.EMAIL_PART})(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>))`, 'gim'),
replacement: (match, g1, g2) => {
if (!Str.isValidMention(match)) {
return match;
}
return `<mention-user>${match}</mention-user>`;
return `${g1}<mention-user>${g2}</mention-user>`;
},
},

{
name: 'hereMentionAfterUserMentions',
regex: /(<\/mention-user>)(@here)(?=\b)/gm,
replacement: '$1<mention-here>$2</mention-here>',
},

/**
* Automatically link urls. Runs last of our linkers since we want anything manual to link before this,
* and we do not want to break emails.
Expand Down

0 comments on commit d24d6fa

Please sign in to comment.