Skip to content
Closed
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
18 changes: 10 additions & 8 deletions __tests__/ExpensiMark-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ test('Test text is escaped', () => {
expect(parser.replace(testString)).toBe(resultString);
});

test('Disallow multiline markdown links (label and URL)', () => {
// Multiline label inside [] should not form a link; URL is auto-linked inside parentheses
test('Allow multiline markdown links (label with newlines)', () => {
// Multiline label inside [] should form a link; newlines in label become <br />
let testString = 'Text with multiline label [Expensi\nfy](https://www.expensify.com) end.';
let resultString = 'Text with multiline label [Expensi<br />fy](<a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">https://www.expensify.com</a>) end.';
let resultString = 'Text with multiline label <a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">Expensi<br />fy</a> end.';
expect(parser.replace(testString)).toBe(resultString);

// Windows-style newline in label -> auto-link URL inside parentheses
// Windows-style newline in label -> link is created, newlines become <br />
testString = 'Text with CRLF label [Expen\r\nsify](https://www.expensify.com) end.';
resultString = 'Text with CRLF label [Expen<br />sify](<a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">https://www.expensify.com</a>) end.';
resultString = 'Text with CRLF label <a href="https://www.expensify.com" target="_blank" rel="noreferrer noopener">Expen<br />sify</a> end.';
expect(parser.replace(testString)).toBe(resultString);
});

test('Do not extract links from multiline markdown link', () => {
test('Extract links from multiline markdown link with multiline label', () => {
const commentLabel = 'Before [Expen\nsify](https://example.com) after';
const commentURL = 'Before [Expensify](https://exa\nmple.com) after';
expect(parser.extractLinksInMarkdownComment(commentLabel)).toStrictEqual([]);
// Multiline label links should now be extracted
expect(parser.extractLinksInMarkdownComment(commentLabel)).toStrictEqual(['https://example.com']);
// Multiline URLs are still not valid links
expect(parser.extractLinksInMarkdownComment(commentURL)).toStrictEqual([]);
});

Expand Down Expand Up @@ -114,7 +116,7 @@ describe('Test ExpensiMark getAttributeCache', () => {
});

test('If no extras are undefined, returns undefined for both attrCachingFn and attrCache', () => {
const {attrCachingFn, attrCache} = expensiMark.getAttributeCache(undefined);
const { attrCachingFn, attrCache } = expensiMark.getAttributeCache(undefined);
expect(attrCachingFn).toBe(undefined);
expect(attrCache).toBe(undefined);
})
Expand Down
2 changes: 1 addition & 1 deletion lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type TruncateOptions = {
removeImageTag?: boolean;
};

const MARKDOWN_LINK_REGEX = new RegExp(`\\[((?:[^\\[\\]\\r\\n]*(?:\\[[^\\[\\]\\r\\n]*][^\\[\\]\\r\\n]*)*))]\\(${UrlPatterns.MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`, 'gi');
const MARKDOWN_LINK_REGEX = new RegExp(`\\[((?:[^\\[\\]]*(?:\\[[^\\[\\]]*][^\\[\\]]*)*))]\\(${UrlPatterns.MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`, 'gi');
const MARKDOWN_IMAGE_REGEX = new RegExp(`\\!(?:\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)])?\\(${UrlPatterns.MARKDOWN_URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`, 'gi');

const MARKDOWN_VIDEO_REGEX = new RegExp(
Expand Down