Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parsing mention wrapped with styles inside link text #549

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,18 +866,6 @@ test('Test for user mention with text with inlineCodeBlock style', () => {
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for user mention inside link markdown', () => {
const testString = '[@[email protected]](expensify.com)';
const resultString = '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener">@[email protected]</a>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for user mention inside email markdown', () => {
const testString = '[@[email protected]]([email protected])';
const resultString = '<a href="mailto:[email protected]">@[email protected]</a>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for user mention without space or supported styling character', () => {
const testString = 'hi@[email protected]';
const resultString = 'hi@<a href=\"mailto:[email protected]\">[email protected]</a>';
Expand Down Expand Up @@ -985,6 +973,52 @@ test('Test for @here mention without space or supported styling character', () =
expect(parser.replace(testString)).toBe(resultString);
});

test('Test for mention inside link and email markdown', () => {
const testString = '[@[email protected]](expensify.com) '
+ '[_@[email protected]_](expensify.com) '
+ '[*@[email protected]*](expensify.com) '
+ '[~@[email protected]~](expensify.com) '
+ '[`@[email protected]`](expensify.com) '
+ '[@here](expensify.com) '
+ '[_@here_](expensify.com) '
+ '[*@here*](expensify.com) '
+ '[~@here~](expensify.com) '
+ '[`@here`](expensify.com) '
+ '[@[email protected]]([email protected]) '
+ '[_@[email protected]_]([email protected]) '
+ '[*@[email protected]*]([email protected]) '
+ '[~@[email protected]~]([email protected]) '
+ '[`@[email protected]`]([email protected]) '
+ '[@here]([email protected]) '
+ '[_@here_]([email protected]) '
+ '[*@here*]([email protected]) '
+ '[~@here~]([email protected]) '
+ '[`@here`]([email protected])';

const resultString = '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener">@[email protected]</a> '
+ '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener"><em>@[email protected]</em></a> '
+ '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener"><strong>@[email protected]</strong></a> '
+ '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener"><del>@[email protected]</del></a> '
+ '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener"><code>@[email protected]</code></a> '
+ '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener">@here</a> '
+ '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener"><em>@here</em></a> '
+ '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener"><strong>@here</strong></a> '
+ '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener"><del>@here</del></a> '
+ '<a href="https://expensify.com" target="_blank" rel="noreferrer noopener"><code>@here</code></a> '
+ '<a href="mailto:[email protected]">@[email protected]</a> '
+ '<a href="mailto:[email protected]"><em>@[email protected]</em></a> '
+ '<a href="mailto:[email protected]"><strong>@[email protected]</strong></a> '
+ '<a href="mailto:[email protected]"><del>@[email protected]</del></a> '
+ '<a href="mailto:[email protected]"><code>@[email protected]</code></a> '
+ '<a href="mailto:[email protected]">@here</a> '
+ '<a href="mailto:[email protected]"><em>@here</em></a> '
+ '<a href="mailto:[email protected]"><strong>@here</strong></a> '
+ '<a href="mailto:[email protected]"><del>@here</del></a> '
+ '<a href="mailto:[email protected]"><code>@here</code></a>';

expect(parser.replace(testString)).toBe(resultString);
});

test('Skip rendering invalid markdown',() => {
let testString = '_*test_*';
expect(parser.replace(testString)).toBe('<em>*test</em>*');
Expand Down
4 changes: 2 additions & 2 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class ExpensiMark {
*/
{
name: 'hereMentions',
regex: /[`.a-zA-Z]?@here(?=_\b|\b)(?![^<]*(<\/pre>|<\/code>|<\/a>))/gm,
regex: /[`.a-zA-Z]?@here(?=_\b|\b)(?!((?:(?!<a).)+)?<\/a>|[^<]*(<\/pre>|<\/code>))/gm,
replacement: (match) => {
if (!Str.isValidMention(match)) {
return match;
Expand All @@ -110,7 +110,7 @@ export default class ExpensiMark {
*/
{
name: 'userMentions',
regex: new RegExp(`[\`.a-zA-Z]?@+${CONST.REG_EXP.EMAIL_PART}(?![^<]*(<\\/pre>|<\\/code>|<\\/a>))`, 'gm'),
regex: new RegExp(`[\`.a-zA-Z]?@+${CONST.REG_EXP.EMAIL_PART}(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>))`, 'gm'),
replacement: (match) => {
if (!Str.isValidMention(match)) {
return match;
Expand Down