Skip to content

Commit

Permalink
fix problems with parsing links with the same emails inside link block
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Nov 15, 2023
1 parent c9d70d3 commit f3af425
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,9 @@ test('Test markdown style email link with various styles', () => {
+ '[ Expensify ]([email protected])' // edge spaces in []
+ '[ Expensify Email ]([email protected])' // space between words in []
+ '[[email protected]]([email protected])' // same email between [] and ()
+ '[[email protected]](mailto:[email protected])' // same email between [] and () with mailto: in href
+ '[mailto:[email protected]]([email protected])' // same email between [] and () with mailto: in text
+ '[mailto:[email protected]](mailto:[email protected])' // same email between [] and () with mailto: in text and href
+ '[[email protected]]([email protected])' // different emails between [] and ()
+ '[(Expensify)]([email protected])' // () in []
+ '[Expensify [Test]([email protected]) Test]([email protected])' // []() in []
Expand All @@ -839,6 +842,9 @@ test('Test markdown style email link with various styles', () => {
+ '<a href="mailto:[email protected]">Expensify</a>'
+ '<a href="mailto:[email protected]">Expensify Email</a>'
+ '<a href="mailto:[email protected]">[email protected]</a>'
+ '<a href="mailto:[email protected]">[email protected]</a>'
+ '<a href="mailto:[email protected]">mailto:[email protected]</a>'
+ '<a href="mailto:[email protected]">mailto:[email protected]</a>'
+ '<a href="mailto:[email protected]">[email protected]</a>'
+ '<a href="mailto:[email protected]">(Expensify)</a>'
+ '[Expensify <a href="mailto:[email protected]">Test</a> Test](<a href="mailto:[email protected]">[email protected]</a>)'
Expand Down
4 changes: 2 additions & 2 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class ExpensiMark {
name: 'email',
process: (textToProcess, replacement) => {
const regex = new RegExp(
`(?!\\[\\s*\\])\\[([^[\\]]*)]\\(${CONST.REG_EXP.MARKDOWN_EMAIL}\\)`, 'gim'
`(?!\\[\\s*\\])\\[([^[\\]]*)]\\((mailto:)?${CONST.REG_EXP.MARKDOWN_EMAIL}\\)`, 'gim'
);
return this.modifyTextForEmailLinks(regex, textToProcess, replacement);
},
Expand Down Expand Up @@ -572,7 +572,7 @@ export default class ExpensiMark {
filterRules: ['bold', 'strikethrough', 'italic'],
shouldEscapeText: false,
});
replacedText = replacedText.concat(replacement(match[0], linkText, match[2]));
replacedText = replacedText.concat(replacement(match[0], linkText, match[3]));
startIndex = match.index + (match[0].length);

// Now we move to the next match that the js regex found in the text
Expand Down

0 comments on commit f3af425

Please sign in to comment.