Skip to content

Commit

Permalink
fix auto email pattern not recognized
Browse files Browse the repository at this point in the history
  • Loading branch information
eh2077 committed Oct 24, 2023
1 parent ba5a50e commit 7cabecc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1442,3 +1442,31 @@ test('Test strikethrough with link with URL that contains tilde', () => {
testString = '~[Example Link](https://example.com/?~example=~~~ex~)~';
expect(parser.replace(testString)).toBe('<del><a href="https://example.com/?~example=~~~ex~" target="_blank" rel="noreferrer noopener">Example Link</a></del>');
});

test('Test autoEmail with markdown of <pre>, <code>, <a>, <mention-user> and <em> tag', () => {
const testString = '`code`[email protected] '
+ '```code block```[email protected] '
+ '[Google](https://google.com)[email protected] '
+ '[email protected]_ '
+ '_test\n\[email protected]_ '
+ '`[email protected]` '
+ '```[email protected]``` '
+ '@[email protected] '
+ '_@[email protected]_ '
+ '[https://staging.new.expensify.com/details/[email protected]](https://staging.new.expensify.com/details/[email protected]) '
+ '[test italic style wrap email [email protected]_ inside a link](https://google.com) ';

const resultString = '<code>code</code><a href="mailto:[email protected]">[email protected]</a> '
+ '<pre>code&#32;block</pre><a href="mailto:[email protected]">[email protected]</a> '
+ '<a href="https://google.com" target="_blank" rel="noreferrer noopener">Google</a><a href="mailto:[email protected]">[email protected]</a> '
+ '<em><a href="mailto:[email protected]">[email protected]</a></em> '
+ '<em>test<br /><br /><a href="mailto:[email protected]">[email protected]</a></em> '
+ '<code>[email protected]</code> '
+ '<pre>[email protected]</pre> '
+ '<mention-user>@[email protected]</mention-user> '
+ '<em><mention-user>@[email protected]</mention-user></em> '
+ '<a href="https://staging.new.expensify.com/details/[email protected]" target="_blank" rel="noreferrer noopener">https://staging.new.expensify.com/details/[email protected]</a> '
+ '<a href="https://google.com" target="_blank" rel="noreferrer noopener">test italic style wrap email <em>[email protected]</em> inside a link</a> ';

expect(parser.replace(testString)).toBe(resultString);
});
2 changes: 1 addition & 1 deletion lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default class ExpensiMark {
{
name: 'autoEmail',
regex: new RegExp(
`(?![^<]*>|[^<>]*<\\/(?!em))([^\\w'#%+-]|^|<em>)${CONST.REG_EXP.MARKDOWN_EMAIL}(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>))`,
`([^\\w'#%+-]|^)${CONST.REG_EXP.MARKDOWN_EMAIL}(?!((?:(?!<a).)+)?<\\/a>|[^<>]*<\\/(?!em))`,
'gim',
),
replacement: '$1<a href="mailto:$2">$2</a>',
Expand Down

0 comments on commit 7cabecc

Please sign in to comment.