From 6c0760a4de2976a06e98118e00314482eebd1838 Mon Sep 17 00:00:00 2001 From: agilejune Date: Tue, 31 Oct 2023 05:27:03 +0100 Subject: [PATCH 1/6] fix-#21753 --- __tests__/ExpensiMark-HTML-test.js | 30 ++++++++++++++++++++++++++++++ lib/ExpensiMark.js | 8 +++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index e5aa6e25..5b5f9f4e 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -1298,6 +1298,36 @@ 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 = '@aiman.chnaif+2@gmail.com@here'; + let resultString = '@aiman.chnaif+2@gmail.com@here'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@here@aiman.chnaif+2@gmail.com'; + resultString = '@here@aiman.chnaif+2@gmail.com'; + expect(parser.replace(testString)).toBe(resultString); + + testString = '@aiman.chnaif+2@gmail.com@aiman.chnaif+2@gmail.com'; + resultString = '@aiman.chnaif+2@gmail.com@aiman.chnaif+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); +}); + 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 ad11ae7f..ea05f99a 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -97,7 +97,7 @@ export default class ExpensiMark { */ { name: 'hereMentions', - regex: /([a-zA-Z0-9.!$%&+/=?^`{|}_-]?)(@here)([a-zA-Z0-9.!$%&+/=?^`{|}_-]?)(?=\b)(?!(@[a-zA-Z0-9-]+?(\.[a-zA-Z]+)+)|((?:(?!|[^<]*(<\/pre>|<\/code>))/gm, + regex: /([^@*~]?)(@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; @@ -124,6 +124,12 @@ export default class ExpensiMark { }, }, + { + 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. From cd50eb3fb3185f671ede918dd7aaa81376b09e04 Mon Sep 17 00:00:00 2001 From: agilejune Date: Wed, 1 Nov 2023 10:49:05 +0100 Subject: [PATCH 2/6] update test case --- __tests__/ExpensiMark-HTML-test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index 5b5f9f4e..ec789f20 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -1299,16 +1299,16 @@ test('Test for @here mention without space or supported styling character', () = }); test('Test user mention and here mention, which are concatenated without space', () => { - let testString = '@aiman.chnaif+2@gmail.com@here'; - let resultString = '@aiman.chnaif+2@gmail.com@here'; + let testString = '@test.example+2@gmail.com@here'; + let resultString = '@test.example+2@gmail.com@here'; expect(parser.replace(testString)).toBe(resultString); - testString = '@here@aiman.chnaif+2@gmail.com'; - resultString = '@here@aiman.chnaif+2@gmail.com'; + testString = '@here@test.example+2@gmail.com'; + resultString = '@here@test.example+2@gmail.com'; expect(parser.replace(testString)).toBe(resultString); - testString = '@aiman.chnaif+2@gmail.com@aiman.chnaif+2@gmail.com'; - resultString = '@aiman.chnaif+2@gmail.com@aiman.chnaif+2@gmail.com'; + 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'; From 77c08a9251ba4b85a396dc309431c841fc03c7ac Mon Sep 17 00:00:00 2001 From: agilejune Date: Tue, 7 Nov 2023 07:19:11 +0100 Subject: [PATCH 3/6] fix 21753 - edge cases of multiple mention --- __tests__/ExpensiMark-HTML-test.js | 16 ++++++++++++++++ lib/ExpensiMark.js | 6 +++--- lib/str.js | 3 ++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index ec789f20..645846c3 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -1326,6 +1326,22 @@ test('Test user mention and here mention, which are concatenated without space', 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', () => { diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index ea05f99a..9619b1ab 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -115,12 +115,12 @@ export default class ExpensiMark { */ { name: 'userMentions', - regex: new RegExp(`[a-zA-Z0-9.!$%&+/=?^\`{|}-]?@+${CONST.REG_EXP.EMAIL_PART}(?!((?:(?!|[^<]*(<\\/pre>|<\\/code>))`, 'gm'), - replacement: (match) => { + regex: new RegExp(`(@here|[a-zA-Z0-9.!$%&+=?^\`{|}-]?)(@+${CONST.REG_EXP.EMAIL_PART})(?!((?:(?!|[^<]*(<\\/pre>|<\\/code>))`, 'gm'), + replacement: (match, g1, g2) => { if (!Str.isValidMention(match)) { return match; } - return `${match}`; + return `${g1}${g2}`; }, }, diff --git a/lib/str.js b/lib/str.js index ad48560e..0da556a5 100644 --- a/lib/str.js +++ b/lib/str.js @@ -944,7 +944,8 @@ const Str = { */ isValidMention(mention) { // Mentions can start @ proceeded by a space, eg "ping @user@domain.tld" - if (/[\s@]/g.test(mention.charAt(0))) { + // or by a @here, eg "@here@user@domain.tld" + if (/[\s@]/g.test(mention.charAt(0)) || /^@here.*/g.test(mention)) { return true; } From b5707f82413d3b10419d2766b397fbb6222104fd Mon Sep 17 00:00:00 2001 From: agilejune Date: Mon, 13 Nov 2023 23:37:00 +0100 Subject: [PATCH 4/6] fix lint --- lib/ExpensiMark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 70d712c2..6d2d0bb9 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -121,7 +121,7 @@ export default class ExpensiMark { */ { name: 'userMentions', - regex: new RegExp(`(@here|[a-zA-Z0-9.!$%&+=?^\`{|}-]?)(@+${CONST.REG_EXP.EMAIL_PART})(?!((?:(?!|[^<]*(<\\/pre>|<\\/code>))`, 'gm'), + 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; From 5d40ac3f38dee66e525766876793aedfe2abc054 Mon Sep 17 00:00:00 2001 From: agilejune Date: Tue, 14 Nov 2023 22:54:55 +0100 Subject: [PATCH 5/6] remove condition --- lib/str.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/str.js b/lib/str.js index 0da556a5..ad48560e 100644 --- a/lib/str.js +++ b/lib/str.js @@ -944,8 +944,7 @@ const Str = { */ isValidMention(mention) { // Mentions can start @ proceeded by a space, eg "ping @user@domain.tld" - // or by a @here, eg "@here@user@domain.tld" - if (/[\s@]/g.test(mention.charAt(0)) || /^@here.*/g.test(mention)) { + if (/[\s@]/g.test(mention.charAt(0))) { return true; } From bdbef094e12aa093dc1c56c6e96639f3d03c2ff0 Mon Sep 17 00:00:00 2001 From: agilejune Date: Sat, 18 Nov 2023 10:22:51 +0100 Subject: [PATCH 6/6] fix here mention --- lib/ExpensiMark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index fdd6aa66..50592e64 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -103,7 +103,7 @@ export default class ExpensiMark { */ { name: 'hereMentions', - regex: /([^@*~]?)(@here)([^@*~]?)(?=\b)(?!([\w'#%+-]*@(?:[a-z\d-]+\.)+[a-z]{2,}(?:\s|$|@here))|((?:(?!|[^<]*(<\/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;