Skip to content

Commit

Permalink
Merge pull request Expensify#714 from nkdengineer/fix/valid-phone-number
Browse files Browse the repository at this point in the history
  • Loading branch information
blimpich authored Jun 11, 2024
2 parents 5c8455f + e533bfa commit 634e3d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<mention-user>@+1234567890</mention-user>';
const resultString = '@+1234567890';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});

test('user mention from valid phone number', () => {
const testString = '@+15005550006';
const resultString = '<mention-user>@+15005550006</mention-user>';
expect(parser.replace(testString, {shouldKeepRawInput: true})).toBe(resultString);
});
});
Expand Down
5 changes: 4 additions & 1 deletion lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ export default class ExpensiMark {
return `${g1}<mention-user>${g2}${phoneRegex.test(g2) ? `@${Constants.CONST.SMS.DOMAIN}` : ''}</mention-user>`;
},
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}<mention-user>${g2}</mention-user>`;
Expand Down

0 comments on commit 634e3d0

Please sign in to comment.