From 285d0d13f9c3af4f709e0fca6ce39fcef90d90e0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 17 Jun 2019 20:15:19 +0900 Subject: [PATCH] Fix MFM URL parsing --- src/mfm/language.ts | 6 ++++-- test/mfm.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/mfm/language.ts b/src/mfm/language.ts index bfa22e8c3..4750ea338 100644 --- a/src/mfm/language.ts +++ b/src/mfm/language.ts @@ -164,8 +164,10 @@ export const mfmLanguage = P.createLanguage({ } else url = match[0]; url = removeOrphanedBrackets(url); - if (url.endsWith('.')) url = url.substr(0, url.lastIndexOf('.')); - if (url.endsWith(',')) url = url.substr(0, url.lastIndexOf(',')); + while (url.endsWith('.') || url.endsWith(',')) { + if (url.endsWith('.')) url = url.substr(0, url.lastIndexOf('.')); + if (url.endsWith(',')) url = url.substr(0, url.lastIndexOf(',')); + } return P.makeSuccess(i + url.length, url); }).map(x => createLeaf('url', { url: x })); }, diff --git a/test/mfm.ts b/test/mfm.ts index c772a62dc..be8b65264 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -804,6 +804,14 @@ describe('MFM', () => { ]); }); + it('ignore trailing periods', () => { + const tokens = parse('https://example.com...'); + assert.deepStrictEqual(tokens, [ + leaf('url', { url: 'https://example.com' }), + text('...') + ]); + }); + it('with comma', () => { const tokens = parse('https://example.com/foo?bar=a,b'); assert.deepStrictEqual(tokens, [