Skip to content

Commit

Permalink
fix: no trimming for link name
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictb committed Aug 5, 2024
1 parent 4f2e0bc commit 265d496
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
10 changes: 6 additions & 4 deletions __tests__/ExpensiMark-HTML-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ test('Test critical markdown style links', () => {
'[link with [brackets] inside of it](https://google.com) ' +
'[link with smart quotes ‘’“”](https://google.com) ' +
'[link with [email protected] email in it](https://google.com)' +
'[Localhost](http://a:3030)';
'[Localhost](http://a:3030)' +
'[ name with rear spaces ](https://example.com)';
const resultString =
'Testing ' +
'<a href="https://expensify.com" target="_blank" rel="noreferrer noopener"><del>strikethrough</del> <strong>bold</strong> <em>italic</em></a> ' +
Expand All @@ -407,7 +408,8 @@ test('Test critical markdown style links', () => {
'<a href="https://google.com" target="_blank" rel="noreferrer noopener">link with [brackets] inside of it</a> ' +
'<a href="https://google.com" target="_blank" rel="noreferrer noopener">link with smart quotes ‘’“”</a> ' +
'<a href="https://google.com" target="_blank" rel="noreferrer noopener">link with [email protected] email in it</a>' +
'<a href="http://a:3030" target="_blank" rel="noreferrer noopener">Localhost</a>';
'<a href="http://a:3030" target="_blank" rel="noreferrer noopener">Localhost</a>' +
'<a href="https://example.com" target="_blank" rel="noreferrer noopener"> name with rear spaces </a>';
expect(parser.replace(testString)).toBe(resultString);
});

Expand Down Expand Up @@ -1032,7 +1034,7 @@ test('Test markdown and url links with inconsistent starting and closing parens'
'[Text text] more text (<a href="https://www.google.com" target="_blank" rel="noreferrer noopener">link [square brackets within] here</a>)' +
'[Text text] more text (<a href="https://www.google.com" target="_blank" rel="noreferrer noopener">link (parenthesis within) here</a>)' +
'[Text text] more text <a href="https://www.google.com" target="_blank" rel="noreferrer noopener">link here</a>' +
'[Text text] more text (<a href="https://www.google.com" target="_blank" rel="noreferrer noopener">link here</a>)' +
'[Text text] more text (<a href="https://www.google.com" target="_blank" rel="noreferrer noopener">link here </a>)' +
'[Text text] more text ((<a href="https://www.google.com" target="_blank" rel="noreferrer noopener">link here</a>))' +
'[Text text] more text [(<a href="https://www.google.com" target="_blank" rel="noreferrer noopener">link here</a>)]' +
'[Text text] more text (<a href="https://www.google.com" target="_blank" rel="noreferrer noopener">link here</a>)[Text text] more text (<a href="https://www.google.com" target="_blank" rel="noreferrer noopener">link here</a>)';
Expand Down Expand Up @@ -2270,7 +2272,7 @@ describe('room mentions', () => {

test('room mention with space inside link should not be rendered', () => {
const testString = '[ #room](google.com/sub#111)';
const resultString = '<a href="https://google.com/sub#111" target="_blank" rel="noreferrer noopener">#room</a>';
const resultString = '<a href="https://google.com/sub#111" target="_blank" rel="noreferrer noopener"> #room</a>';
expect(parser.replace(testString)).toBe(resultString);
});

Expand Down
9 changes: 4 additions & 5 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ export default class ExpensiMark {
if (!g1.trim()) {
return match;
}
return `<a href="${Str.sanitizeURL(g2)}" target="_blank" rel="noreferrer noopener">${g1.trim()}</a>`;
return `<a href="${Str.sanitizeURL(g2)}" target="_blank" rel="noreferrer noopener">${g1}</a>`;
},
rawInputReplacement: (_extras, match, g1, g2) => {
if (!g1.trim()) {
return match;
}
return `<a href="${Str.sanitizeURL(g2)}" data-raw-href="${g2}" data-link-variant="labeled" target="_blank" rel="noreferrer noopener">${g1.trim()}</a>`;
return `<a href="${Str.sanitizeURL(g2)}" data-raw-href="${g2}" data-link-variant="labeled" target="_blank" rel="noreferrer noopener">${g1}</a>`;
},
},

Expand Down Expand Up @@ -298,10 +298,9 @@ export default class ExpensiMark {
{
name: 'reportMentions',

regex: /(?<![^ \n*~_])(#[\p{Ll}0-9-]{1,80})(?![^<]*(?:<\/pre>|<\/code>))/gimu,
replacement: '<mention-report>$1</mention-report>',
regex: /(?<![^ \n*~_])(#[\p{Ll}0-9-]{1,80})(?![^<]*(?:<\/pre>|<\/code>|<\/a>))/gimu,
replacement: '<mention-report>$1</mention-report>'

Check failure on line 302 in lib/ExpensiMark.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
},

/**
* This regex matches a valid user mention in a string.
* A user mention is a string that starts with the '@' symbol and is followed by a valid user's primary
Expand Down

0 comments on commit 265d496

Please sign in to comment.