From 76693138d3823874a7e5233e06c72eca61c06105 Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Tue, 2 Jul 2019 20:05:52 +0900
Subject: [PATCH] Fix MFM parsing: Ignore parent [] of URL

---
 src/mfm/language.ts | 4 ++--
 test/mfm.ts         | 9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/mfm/language.ts b/src/mfm/language.ts
index 75a2baaab..5d5e35fbf 100644
--- a/src/mfm/language.ts
+++ b/src/mfm/language.ts
@@ -6,8 +6,8 @@ import { toUnicode } from 'punycode';
 import { emojiRegex } from '../misc/emoji-regex';
 
 export function removeOrphanedBrackets(s: string): string {
-	const openBrackets = ['(', '「'];
-	const closeBrackets = [')', '」'];
+	const openBrackets = ['(', '「', '['];
+	const closeBrackets = [')', '」', ']'];
 	const xs = cumulativeSum(s.split('').map(c => {
 		if (openBrackets.includes(c)) return 1;
 		if (closeBrackets.includes(c)) return -1;
diff --git a/test/mfm.ts b/test/mfm.ts
index be8b65264..8ef72c9f8 100644
--- a/test/mfm.ts
+++ b/test/mfm.ts
@@ -843,6 +843,15 @@ describe('MFM', () => {
 				]);
 			});
 
+			it('ignore parent []', () => {
+				const tokens = parse('[https://example.com/foo]');
+				assert.deepStrictEqual(tokens, [
+					text('['),
+					leaf('url', { url: 'https://example.com/foo' }),
+					text(']')
+				]);
+			});
+
 			it('ignore parent brackets 2', () => {
 				const tokens = parse('(foo https://example.com/foo)');
 				assert.deepStrictEqual(tokens, [