Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the issue that inconsistent highlighting occurs when multiple mentions are used without spaces #594

Merged
merged 10 commits into from
Nov 19, 2023
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', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use general emails, not mine 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's updated with general ones

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also update Step 2 in Tests as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done as well

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: /([^@*~]?)(@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
Loading