From 15b54752f0a66dc378b1a19fe93ef06cc930023d Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 10 Jun 2024 10:49:15 +0700 Subject: [PATCH 1/2] fix metion preview with invalid phone number --- lib/ExpensiMark.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index afc4bcad..c1f437ff 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -214,7 +214,10 @@ export default class ExpensiMark { return `${g1}${g2}${phoneRegex.test(g2) ? `@${Constants.CONST.SMS.DOMAIN}` : ''}`; }, rawInputReplacement: (match, g1, g2) => { - if (!Str.isValidMention(match)) { + const phoneNumberRegex = new RegExp(`^${Constants.CONST.REG_EXP.PHONE_PART}$`); + const mention = g2.slice(1); + const mentionWithoutSMSDomain = Str.removeSMSDomain(mention); + if (!Str.isValidMention(match) || (phoneNumberRegex.test(mentionWithoutSMSDomain) && !Str.isValidPhoneNumber(mentionWithoutSMSDomain))) { return match; } return `${g1}${g2}`; From e533bfa23b2088d598b2f82deec3841d540f75f2 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 10 Jun 2024 10:54:02 +0700 Subject: [PATCH 2/2] add test case --- __tests__/ExpensiMark-HTML-test.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index f774b737..763df5b6 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -1844,9 +1844,15 @@ describe('when should keep raw input flag is enabled', () => { expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString); }); - test('user mention from phone number', () => { + test('user mention from invalid phone number', () => { const testString = '@+1234567890'; - const resultString = '@+1234567890'; + const resultString = '@+1234567890'; + expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString); + }); + + test('user mention from valid phone number', () => { + const testString = '@+15005550006'; + const resultString = '@+15005550006'; expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString); }); });