Skip to content

Commit

Permalink
Merge pull request #707 from software-mansion-labs/@szymczak/phone-nu…
Browse files Browse the repository at this point in the history
…mber-mention-not-deleting-smsdomain

Fix phone number mention not deleting sms domain, when editing comment
  • Loading branch information
stitesExpensify authored May 27, 2024
2 parents 84ac039 + 7cb4212 commit c3cc2c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions __tests__/ExpensiMark-Markdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,10 @@ test('Mention user html to markdown', () => {
testString = '<mention-user>@[email protected]</mention-user>';
expect(parser.htmlToMarkdown(testString)).toBe('@[email protected]');

// When there is a phone number mention the sms domain `@expensify.sms`should be removed from returned string
testString = '<mention-user>@[email protected]</mention-user>';
expect(parser.htmlToMarkdown(testString)).toBe('@+311231231');

// When there is `accountID` and no `extras`, `@Hidden` should be returned
testString = '<mention-user accountID="1234"/>';
expect(parser.htmlToMarkdown(testString)).toBe('@Hidden');
Expand Down
19 changes: 11 additions & 8 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,18 @@ export default class ExpensiMark {
},
{
name: 'userMention',
regex: /<mention-user accountID="(\d+)" *\/>/gi,
replacement: (match, g1, offset, string, extras) => {
const accountToNameMap = extras.accountIdToName;
if (!accountToNameMap || !accountToNameMap[g1]) {
Log.alert('[ExpensiMark] Missing account name', {accountID: g1});
return '@Hidden';
regex: /(?:<mention-user accountID="(\d+)" *\/>)|(?:<mention-user>(.*?)<\/mention-user>)/gi,
replacement: (match, g1, g2, offset, string, extras) => {
if (g1) {
const accountToNameMap = extras.accountIdToName;
if (!accountToNameMap || !accountToNameMap[g1]) {
Log.alert('[ExpensiMark] Missing account name', {accountID: g1});
return '@Hidden';
}

return `@${extras.accountIdToName[g1]}`;
}

return `@${extras.accountIdToName[g1]}`;
return Str.removeSMSDomain(g2)
},
},
];
Expand Down

0 comments on commit c3cc2c0

Please sign in to comment.