diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index 433a13bc..f789fb8e 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -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 = '@test.example+2@gmail.com@here'; + let resultString = '@test.example+2@gmail.com@here'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@here@test.example+2@gmail.com'; + resultString = '@here@test.example+2@gmail.com'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@test.example+2@gmail.com@test.example+2@gmail.com'; + resultString = '@test.example+2@gmail.com@test.example+2@gmail.com'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@here@here@gmail.com'; + resultString = '@here@here@gmail.com'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@here@gmail.com@here'; + resultString = '@here@gmail.com@here'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@here@here+1@gmail.com'; + resultString = '@here@here+1@gmail.com'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@here+1@gmail.com@here'; + resultString = '@here+1@gmail.com@here'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@here@gmail.com@here@here@gmail.com'; + resultString = '@here@gmail.com@here@here@gmail.com'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@here@gmail.com@here@here+1@gmail.com'; + resultString = '@here@gmail.com@here@here+1@gmail.com'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@here+1@gmail.com@here@here+2@gmail.com'; + resultString = '@here+1@gmail.com@here@here+2@gmail.com'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@here+1@gmail.com@here@here@here+2@gmail.com@here@here@gmail.com'; + resultString = '@here+1@gmail.com@here@here@here+2@gmail.com@here@here@gmail.com'; + expect(parser.replace(testString)).toBe(resultString); +}); + test('Test for mention inside link and email markdown', () => { const testString = '[@username@expensify.com](expensify.com) ' + '[_@username@expensify.com_](expensify.com) ' diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index e12a5ff1..50592e64 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -103,7 +103,7 @@ export default class ExpensiMark { */ { name: 'hereMentions', - regex: /([a-zA-Z0-9.!$%&+/=?^`{|}_-]?)(@here)([.!$%&+/=?^`{|}_-]?)(?=\b)(?!(@[a-zA-Z0-9-]+?(\.[a-zA-Z]+)+)|((?:(?!|[^<]*(<\/pre>|<\/code>))/gm, + regex: /([a-zA-Z0-9.!$%&+/=?^`{|}_-]?)(@here)([.!$%&+/=?^`{|}_-]?)(?=\b)(?!([\w'#%+-]*@(?:[a-z\d-]+\.)+[a-z]{2,}(?:\s|$|@here))|((?:(?!|[^<]*(<\/pre>|<\/code>))/gm, replacement: (match, g1, g2, g3) => { if (!Str.isValidMention(match)) { return match; @@ -121,15 +121,21 @@ export default class ExpensiMark { */ { name: 'userMentions', - regex: new RegExp(`[a-zA-Z0-9.!$%&+/=?^\`{|}-]?@+${CONST.REG_EXP.EMAIL_PART}(?!((?:(?!|[^<]*(<\\/pre>|<\\/code>))`, 'gmi'), - replacement: (match) => { + regex: new RegExp(`(@here|[a-zA-Z0-9.!$%&+=?^\`{|}-]?)(@+${CONST.REG_EXP.EMAIL_PART})(?!((?:(?!|[^<]*(<\\/pre>|<\\/code>))`, 'gim'), + replacement: (match, g1, g2) => { if (!Str.isValidMention(match)) { return match; } - return `${match}`; + return `${g1}${g2}`; }, }, + { + name: 'hereMentionAfterUserMentions', + regex: /(<\/mention-user>)(@here)(?=\b)/gm, + replacement: '$1$2', + }, + /** * 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.