diff --git a/test/api/unit/libs/highlightMentions.test.js b/test/api/unit/libs/highlightMentions.test.js index a68cd9d6d7..678f2d7178 100644 --- a/test/api/unit/libs/highlightMentions.test.js +++ b/test/api/unit/libs/highlightMentions.test.js @@ -105,4 +105,18 @@ describe('highlightMentions', () => { expect(result[0]).to.equal('[@user](/profile/111) `@user`'); }); }); + + it('github issue 12118, method crashes when square brackets are used', async () => { + const text = '[test]'; + + let err; + + try { + await highlightMentions(text); + } catch (e) { + err = e; + } + + expect(err).to.be.undefined; + }); }); diff --git a/website/server/libs/highlightMentions.js b/website/server/libs/highlightMentions.js index a50c490593..9876522060 100644 --- a/website/server/libs/highlightMentions.js +++ b/website/server/libs/highlightMentions.js @@ -76,7 +76,9 @@ function createCodeBlockRegex ({ content, type, markup }) { */ function findTextAndCodeBlocks (text) { // For token description see https://markdown-it.github.io/markdown-it/#Token - const tokens = habiticaMarkdown.parse(text); + // The second parameter is mandatory even if not used, see + // https://markdown-it.github.io/markdown-it/#MarkdownIt.parse + const tokens = habiticaMarkdown.parse(text, {}); const codeBlocks = findCodeBlocks(tokens); const blocks = [];