From 1536232f8b82dd35f01f3c445a0548651d3ec473 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 5 Mar 2019 22:18:29 +0900 Subject: [PATCH] [MFM] Improve hashtag parsing --- src/mfm/language.ts | 2 +- test/mfm.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mfm/language.ts b/src/mfm/language.ts index bfb0f249c..60e4935ed 100644 --- a/src/mfm/language.ts +++ b/src/mfm/language.ts @@ -142,7 +142,7 @@ export const mfmLanguage = P.createLanguage({ }, hashtag: () => P((input, i) => { const text = input.substr(i); - const match = text.match(/^#([^\s\.,!\?'"#:\/]+)/i); + const match = text.match(/^#([^\s\.,!\?'"#:\/\[\]]+)/i); if (!match) return P.makeFailure(i, 'not a hashtag'); let hashtag = match[1]; hashtag = removeOrphanedBrackets(hashtag); diff --git a/test/mfm.ts b/test/mfm.ts index 7db94b45e..fa46c3ff0 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -550,6 +550,14 @@ describe('MFM', () => { ]); }); + it('ignore square brackets', () => { + const tokens = parse('#foo]'); + assert.deepStrictEqual(tokens, [ + leaf('hashtag', { hashtag: 'foo' }), + text(']'), + ]); + }); + it('allow including number', () => { const tokens = parse('#foo123'); assert.deepStrictEqual(tokens, [