Skip to content

Commit

Permalink
U+FE0Fなどを空文字として返すように
Browse files Browse the repository at this point in the history
  • Loading branch information
ikasoba committed Dec 26, 2023
1 parent 6aaf680 commit d5dfdd3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/internal/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ export const language = P.createLanguage({

unicodeEmoji: r => {
const emoji = RegExp(twemojiRegex.source);
return P.regexp(emoji).map(content => M.UNI_EMOJI(content));
return P.regexp(emoji).map(content => {
// 異体字セレクタのみの場合は空文字として返す
return /^[\uFE00-\uFE0F]+$/u.test(content) ? M.TEXT('') : M.UNI_EMOJI(content);
});
},

plainTag: r => {
Expand Down
6 changes: 6 additions & 0 deletions test/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ describe('SimpleParser', () => {
const output = [TEXT('あ'), EMOJI_CODE('bar'), TEXT('い')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
});

test('U+FE0F', () => {
const input = '\uFE0F';
const output = [TEXT('')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
})
});

test('disallow other syntaxes', () => {
Expand Down

0 comments on commit d5dfdd3

Please sign in to comment.