From 52d02cb38cc01ee664dd8c3ec53bffc91f72c652 Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Wed, 28 Jul 2021 00:12:43 +0530 Subject: [PATCH 1/3] fix(md-link-regex): Fixed regex to support characters between [] --- lib/ExpensiMark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ExpensiMark.js b/lib/ExpensiMark.js index 811bd4be..7704e4b7 100644 --- a/lib/ExpensiMark.js +++ b/lib/ExpensiMark.js @@ -73,7 +73,7 @@ export default class ExpensiMark { process: (textToProcess, replacement) => { const regex = new RegExp( - `\\[((?:[\\w\\s\\d!?&#;:\\/\\-\\.\\+=<>,@\\[\\]‘’“”]|(?:.+<\\/code>))+)\\]\\(${URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`, + `\\[(.+?)\\]\\(${URL_REGEX}\\)(?![^<]*(<\\/pre>|<\\/code>))`, 'gi' ); return this.modifyTextForUrlLinks(regex, textToProcess, replacement); From 789a24b1c5698d57a43601d82ec85e055b93516b Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Wed, 28 Jul 2021 00:13:51 +0530 Subject: [PATCH 2/3] test(md-link-regex): Added tests for parentheses cases --- __tests__/ExpensiMark-HTML-test.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index 80ecf6ea..6baed9f4 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -334,7 +334,10 @@ test('Test markdown and url links with inconsistent starting and closing parens' + '(http://foo.com/(something)?after=parens) ' + '(((http://foo.com/(something)?after=parens ' + '(((http://foo.com/(something)?after=parens))) ' - + 'http://foo.com/(something)?after=parens))) '; + + 'http://foo.com/(something)?after=parens))) ' + + '[Yo (click here to see a cool cat)](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) ' + + '[Yo click here to see a cool cat)](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) ' + + '[Yo (click here to see a cool cat](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) '; const resultString = 'google ' + '(google) ' @@ -344,7 +347,10 @@ test('Test markdown and url links with inconsistent starting and closing parens' + '(http://foo.com/(something)?after=parens) ' + '(((http://foo.com/(something)?after=parens ' + '(((http://foo.com/(something)?after=parens))) ' - + 'http://foo.com/(something)?after=parens))) '; + + 'http://foo.com/(something)?after=parens))) ' + + 'Yo (click here to see a cool cat) ' + + 'Yo click here to see a cool cat) ' + + 'Yo (click here to see a cool cat '; expect(parser.replace(testString)).toBe(resultString); }); From 530a412e0092ea3616a4d046261ae7d68779da14 Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Wed, 28 Jul 2021 00:15:03 +0530 Subject: [PATCH 3/3] test(md-link-regex): Additional test for special characters --- __tests__/ExpensiMark-HTML-test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/__tests__/ExpensiMark-HTML-test.js b/__tests__/ExpensiMark-HTML-test.js index 6baed9f4..aa29ac13 100644 --- a/__tests__/ExpensiMark-HTML-test.js +++ b/__tests__/ExpensiMark-HTML-test.js @@ -337,7 +337,8 @@ test('Test markdown and url links with inconsistent starting and closing parens' + 'http://foo.com/(something)?after=parens))) ' + '[Yo (click here to see a cool cat)](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) ' + '[Yo click here to see a cool cat)](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) ' - + '[Yo (click here to see a cool cat](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) '; + + '[Yo (click here to see a cool cat](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) ' + + '[Yo click * $ & here to see a cool cat](https://c8.alamy.com/compes/ha11pc/cookie-cat-con-sombrero-de-cowboy-y-sun-glass-ha11pc.jpg) '; const resultString = 'google ' + '(google) ' @@ -350,7 +351,8 @@ test('Test markdown and url links with inconsistent starting and closing parens' + 'http://foo.com/(something)?after=parens))) ' + 'Yo (click here to see a cool cat) ' + 'Yo click here to see a cool cat) ' - + 'Yo (click here to see a cool cat '; + + 'Yo (click here to see a cool cat ' + + 'Yo click * $ & here to see a cool cat '; expect(parser.replace(testString)).toBe(resultString); });