diff --git a/test/api/unit/libs/highlightMentions.test.js b/test/api/unit/libs/highlightMentions.test.js index 4495f8cbbc..a450cf9640 100644 --- a/test/api/unit/libs/highlightMentions.test.js +++ b/test/api/unit/libs/highlightMentions.test.js @@ -171,28 +171,32 @@ describe('highlightMentions', () => { it('github issue 12118, method crashes when square brackets are used', async () => { const text = '[test]'; - let err; + const result = await highlightMentions(text); - try { - await highlightMentions(text); - } catch (e) { - err = e; - } - - expect(err).to.be.undefined; + expect(result[0]).to.equal(text); }); it('github issue 12138, method crashes when regex chars are used in code block', async () => { const text = '`[test]`'; - let err; + const result = await highlightMentions(text); - try { - await highlightMentions(text); - } catch (e) { - err = e; - } + expect(result[0]).to.equal(text); + }); - expect(err).to.be.undefined; + it('github issue 12586, method crashes when empty link is used', async () => { + const text = '[]()'; + + const result = await highlightMentions(text); + + expect(result[0]).to.equal(text); + }); + + it('github issue 12586, method crashes when link without title is used', async () => { + const text = '[](www.google.com)'; + + const result = await highlightMentions(text); + + expect(result[0]).to.equal(text); }); }); diff --git a/website/server/libs/highlightMentions.js b/website/server/libs/highlightMentions.js index 7afe0cff6b..39f6a1fcc5 100644 --- a/website/server/libs/highlightMentions.js +++ b/website/server/libs/highlightMentions.js @@ -94,7 +94,7 @@ function toSourceMapRegex (token) { } else if (type === 'code_inline') { regexStr = `${markup} ?${contentRegex} ?${markup}`; } else if (type === 'link_open') { - const texts = token.textContents.map(escapeRegExp); + const texts = token.textContents ? token.textContents.map(escapeRegExp) : ['']; regexStr = markup === 'linkify' || markup === 'autolink' ? texts[0] : `\\[[^\\]]*${texts.join('[^\\]]*')}[^\\]]*\\]\\([^)]*\\)`; } else {