Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: U+FE0Fなどがそのまま絵文字としてパースされてしまう #137

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/internal/parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as M from '..';

Check failure on line 1 in src/internal/parser.ts

View workflow job for this annotation

GitHub Actions / test (16.10.0)

Type '() => P.Parser<M.MfmUnicodeEmoji | M.MfmText>' is not assignable to type '(r: ParserTable<TypeTable>) => Parser<MfmUnicodeEmoji>'.

Check failure on line 1 in src/internal/parser.ts

View workflow job for this annotation

GitHub Actions / report

Type '() => P.Parser<M.MfmUnicodeEmoji | M.MfmText>' is not assignable to type '(r: ParserTable<TypeTable>) => Parser<MfmUnicodeEmoji>'.
import * as P from './core';
import { mergeText } from './util';

Expand All @@ -7,7 +7,7 @@
// このエラーを無視する。
/* eslint @typescript-eslint/ban-ts-comment: 1 */
// @ts-ignore
import twemojiRegex from '@twemoji/parser/dist/lib/regex';

Check warning on line 10 in src/internal/parser.ts

View workflow job for this annotation

GitHub Actions / lint

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free

type ArgPair = { k: string, v: string | true };
type Args = Record<string, string | true>;
Expand Down Expand Up @@ -420,7 +420,10 @@

unicodeEmoji: r => {
const emoji = RegExp(twemojiRegex.source);
return P.regexp(emoji).map(content => M.UNI_EMOJI(content));
return P.regexp(emoji).map(content => {
// 異体字セレクタ(U+FE0F)の場合は文字として返す
return content === '\uFE0F' ? M.TEXT(content) : 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('Ignore Variation Selector preceded by Unicode Emoji', () => {
const input = '\uFE0F';
const output = [TEXT('')];
assert.deepStrictEqual(mfm.parseSimple(input), output);
})
});

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