From dbbc416095ae39541dc3f3de1ce24966a290ac61 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 5a20c7ef2b..3edb23b602 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 8ca09c7417..206105bc56 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([