From 1d1024c57a2067d7fe0f6e1e97cd8df584481892 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 23 Nov 2018 16:02:17 +0900 Subject: [PATCH] [MFM] Improve hashtag detection Resolve #3387 --- src/mfm/parser.ts | 1 + test/mfm.ts | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/mfm/parser.ts b/src/mfm/parser.ts index 047124e582..5a20c7ef2b 100644 --- a/src/mfm/parser.ts +++ b/src/mfm/parser.ts @@ -112,6 +112,7 @@ const mfm = P.createLanguage({ const text = input.substr(i); const match = text.match(/^#([^\s\.,!\?#]+)/i); if (!match) return P.makeFailure(i, 'not a hashtag'); + if (match[1].match(/[0-9]+/)) return P.makeFailure(i, 'not a hashtag'); if (input[i - 1] != '\n' && input[i - 1] != ' ' && input[i - 1] != null) return P.makeFailure(i, 'require space before "#"'); return P.makeSuccess(i + match[0].length, makeNode('hashtag', { hashtag: match[1] })); }), diff --git a/test/mfm.ts b/test/mfm.ts index a40f769f80..8ca09c7417 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -204,6 +204,13 @@ describe('Text', () => { text('!'), ], tokens); }); + + it('disallow number only', () => { + const tokens = analyze('#123'); + assert.deepEqual([ + text('#123'), + ], tokens); + }); }); describe('quote', () => {