From d75a6faeba474b4eb0d5a43387e4ae019e1a4e15 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 24 Nov 2018 17:18:11 +0900 Subject: [PATCH] [MFM] Fix hashtag detection --- src/mfm/parser.ts | 2 +- test/mfm.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mfm/parser.ts b/src/mfm/parser.ts index 5a20c7ef2..3edb23b60 100644 --- a/src/mfm/parser.ts +++ b/src/mfm/parser.ts @@ -112,7 +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 (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 8ca09c741..206105bc5 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -205,6 +205,13 @@ describe('Text', () => { ], tokens); }); + it('allow including number', () => { + const tokens = analyze('#foo123'); + assert.deepEqual([ + node('hashtag', { hashtag: 'foo123' }), + ], tokens); + }); + it('disallow number only', () => { const tokens = analyze('#123'); assert.deepEqual([