From 85d290a1fa41356b7552bed8cf2ad0511724ce60 Mon Sep 17 00:00:00 2001 From: Bart Enkelaar Date: Tue, 19 May 2020 17:28:55 +0200 Subject: [PATCH] fix(chat) - Issue 12217 - Allow url-escapable characters in links. (#12218) --- test/api/unit/libs/highlightMentions.test.js | 7 +++++++ website/server/libs/highlightMentions.js | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/api/unit/libs/highlightMentions.test.js b/test/api/unit/libs/highlightMentions.test.js index e00e23950b..492bed033e 100644 --- a/test/api/unit/libs/highlightMentions.test.js +++ b/test/api/unit/libs/highlightMentions.test.js @@ -100,6 +100,13 @@ describe('highlightMentions', () => { const result = await highlightMentions(text); expect(result[0]).to.equal('http://www.medium.com/@user/blog [@user](/profile/111)'); }); + + // https://github.com/HabitRPG/habitica/issues/12217 + it('doesn\'t highlight user in link with url-escapable characters', async () => { + const text = '[test](https://habitica.fandom.com/ru/@wiki/Снаряжение)'; + const result = await highlightMentions(text); + expect(result[0]).to.equal(text); + }); }); describe('exceptions in code blocks', () => { diff --git a/website/server/libs/highlightMentions.js b/website/server/libs/highlightMentions.js index da01db9d3e..900a9547a0 100644 --- a/website/server/libs/highlightMentions.js +++ b/website/server/libs/highlightMentions.js @@ -86,7 +86,7 @@ function toSourceMapRegex (token) { } else if (type === 'link_open') { const texts = token.textContents.map(escapeRegExp); regexStr = markup === 'linkify' || markup === 'autolink' ? texts[0] - : `\\[.*${texts.join('.*')}.*\\]\\(${escapeRegExp(token.attrs[0][1])}\\)`; + : `\\[.*${texts.join('.*')}.*\\]\\([^)]+\\)`; } else { throw new Error(`No source mapping regex defined for ignore blocks of type ${type}`); }