Keep keycap emojis intact when stripping invisible characters

This commit is contained in:
Kalle
2026-10-27 16:50:17 +02:00
parent dc2070f005
commit 6e8aef0ec6
2 changed files with 11 additions and 3 deletions

View File

@@ -115,10 +115,17 @@ describe("actuallyNonEmptyStringOrNull", () => {
});
test.each([
{ why: "rainbow flag", value: "she/her \ud83c\udff3\ufe0f\u200d\ud83c\udf08" },
{
why: "rainbow flag",
value: "she/her \ud83c\udff3\ufe0f\u200d\ud83c\udf08",
},
{ why: "transgender flag", value: "\ud83c\udff3\ufe0f\u200d\u26a7\ufe0f" },
{ why: "family", value: "\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc67" },
{
why: "family",
value: "\ud83d\udc68\u200d\ud83d\udc69\u200d\ud83d\udc67",
},
{ why: "emoji presentation heart", value: "GG \u2764\ufe0f" },
{ why: "keycap", value: "1\ufe0f\u20e3 2\ufe0f\u20e3 #\ufe0f\u20e3" },
])("keeps the joiners and selectors of an emoji ($why)", ({ value }) => {
expect(actuallyNonEmptyStringOrNull(value)).toBe(value);
});

View File

@@ -440,8 +440,9 @@ const EMPTY_CHARACTERS = [
];
const EMOJI_PART = "\\p{Extended_Pictographic}(?:\\uFE0F|\\p{Emoji_Modifier})?";
const EMOJI_SEQUENCE = `${EMOJI_PART}(?:\\u200D${EMOJI_PART})*`;
const KEYCAP_SEQUENCE = "[0-9#*]\\uFE0F?\\u20E3";
const EMOJI_SEQUENCE_OR_EMPTY_CHARACTER_REGEX = new RegExp(
`(${EMOJI_SEQUENCE})|${EMPTY_CHARACTERS.join("|")}`,
`(${EMOJI_SEQUENCE}|${KEYCAP_SEQUENCE})|${EMPTY_CHARACTERS.join("|")}`,
"gu",
);