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: move autoEmail to before mentions #550

Merged
merged 10 commits into from
Jul 12, 2023
60 changes: 60 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,3 +1048,63 @@ test('Skip rendering invalid markdown',() => {
testString = '> *This is multiline\nbold text*';
expect(parser.replace(testString)).toBe('<blockquote>*This is multiline</blockquote>bold text*');
});

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

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

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

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

test('Test user mention with @[email protected]', () => {
const testString = '@[email protected]';
const resultString = '<mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test user mention with @[email protected]', () => {
const testString = '@[email protected]';
const resultString = '<mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test user mention with @[email protected]', () => {
const testString = '@[email protected]';
const resultString = '<mention-user>@[email protected]</mention-user>';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test here mention with @here_@here_.com', () => {
const testString = '@here_@here_.com';
const resultString = '<mention-here>@here</mention-here><em><mention-here>@here</mention-here></em>.com';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test here mention with @here@', () => {
const testString = '@here@';
const resultString = '<mention-here>@here</mention-here>@';
expect(parser.replace(testString)).toBe(resultString);
});

test('Test here mention with @here@here', () => {
const testString = '@here@here';
const resultString = '<mention-here>@here</mention-here><mention-here>@here</mention-here>';
expect(parser.replace(testString)).toBe(resultString);
});
1 change: 0 additions & 1 deletion __tests__/Str-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ describe('Str.isValidMention', () => {
expect(Str.isValidMention('*@[email protected]*')).toBeTruthy();
expect(Str.isValidMention(' @[email protected]')).toBeTruthy();
expect(Str.isValidMention('~@[email protected]~')).toBeTruthy();
expect(Str.isValidMention('#@[email protected]')).toBeTruthy();
expect(Str.isValidMention('_@[email protected]_')).toBeTruthy();
expect(Str.isValidMention('`@[email protected]`')).toBeFalsy();
expect(Str.isValidMention('\'@[email protected]\'')).toBeTruthy();
Expand Down
8 changes: 4 additions & 4 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ export default class ExpensiMark {
*/
{
name: 'hereMentions',
regex: /[`.a-zA-Z]?@here(?=_\b|\b)(?!((?:(?!<a).)+)?<\/a>|[^<]*(<\/pre>|<\/code>))/gm,
replacement: (match) => {
regex: /([a-zA-Z0-9.!$%&+/=?^`{|}_-]?)(@here)([a-zA-Z0-9.!$%&+/=?^`{|}_-]?)(?=\b)(?!(@[a-zA-Z0-9-]+?(\.[a-zA-Z]+)+)|((?:(?!<a).)+)?<\/a>|[^<]*(<\/pre>|<\/code>))/gm,
replacement: (match, g1, g2, g3) => {
if (!Str.isValidMention(match)) {
return match;
}
return `<mention-here>${match}</mention-here>`;
return `${g1}<mention-here>${g2}</mention-here>${g3}`;
},
},

Expand All @@ -110,7 +110,7 @@ export default class ExpensiMark {
*/
{
name: 'userMentions',
regex: new RegExp(`[\`.a-zA-Z]?@+${CONST.REG_EXP.EMAIL_PART}(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>))`, 'gm'),
regex: new RegExp(`[a-zA-Z0-9.!$%&+/=?^\`{|}-]?@+${CONST.REG_EXP.EMAIL_PART}(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>))`, 'gm'),
replacement: (match) => {
if (!Str.isValidMention(match)) {
return match;
Expand Down
10 changes: 8 additions & 2 deletions lib/str.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,14 @@ const Str = {
* @returns {bool}
*/
isValidMention(mention) {
// A valid mention starts with a space, *, _, #, ', ", or @ (with no preceding characters).
return /[\s*~_#'"@]/g.test(mention.charAt(0));
// A valid mention starts with a space or @, or
// starts and ends with a *, _, #, ', or " (with no preceding characters).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is # supposed to be here? I thought # was used for headings like so # heading 1, ie, with a # before the text but without a # after the text

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A valid mention starts with a space or @ or starts and ends with a *, _, #, ', or " (with no preceding characters)

Is this correct?
I think I'm missing something, can mention start and end with *, _, #, ', or "?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eVoloshchak it can "start" with * in the sense that the mention can be within two *, so it'll still technically start with an @, but this is saying it can start with * becasue it can be like let's ask *@[email protected]*.

This is why I asked about #, cause that one is only a leading character unlike *, _, ', ", and ~.

Incidentally @tienifr, the ~ is missing from the comment starts and ends with a *, _, #, ', or "...

Copy link
Contributor Author

@tienifr tienifr Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incidentally @tienifr, the ~ is missing from the comment starts and ends with a *, _, #, ', or "...

I missed that. Thanks for pointing it out.

This is why I asked about #, cause that one is only a leading character unlike *, _, ', ", and ~.

I agree that # is redundant here since it is only a leading character, and we can get rid of it. It also does not affect the current behavior of either this PR or the current staging version
image

if (/[\s@]/g.test(mention.charAt(0))) {
return true;
}
tienifr marked this conversation as resolved.
Show resolved Hide resolved
const firstChar = mention.charAt(0);
const lastChar = mention.charAt(mention.length - 1);
return /[*~_#'"]/g.test(firstChar) && /[*~_#'"]/g.test(lastChar) && firstChar === lastChar;
},

/**
Expand Down