mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-11-18 12:46:58 -06:00
Keep emoji sequences intact when stripping invisible characters
This commit is contained in:
@@ -113,6 +113,15 @@ describe("actuallyNonEmptyStringOrNull", () => {
|
||||
expect(actuallyNonEmptyStringOrNull("\ufe0e")).toBeNull();
|
||||
expect(actuallyNonEmptyStringOrNull("\ufe0e\ufe0e")).toBeNull();
|
||||
});
|
||||
|
||||
test.each([
|
||||
{ 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: "emoji presentation heart", value: "GG \u2764\ufe0f" },
|
||||
])("keeps the joiners and selectors of an emoji ($why)", ({ value }) => {
|
||||
expect(actuallyNonEmptyStringOrNull(value)).toBe(value);
|
||||
});
|
||||
});
|
||||
|
||||
describe("hexCodeWithoutAlpha", () => {
|
||||
|
||||
@@ -438,7 +438,12 @@ const EMPTY_CHARACTERS = [
|
||||
"\u2060",
|
||||
"[\\uFE00-\\uFE0F]",
|
||||
];
|
||||
const EMPTY_CHARACTERS_REGEX = new RegExp(EMPTY_CHARACTERS.join("|"), "g");
|
||||
const EMOJI_PART = "\\p{Extended_Pictographic}(?:\\uFE0F|\\p{Emoji_Modifier})?";
|
||||
const EMOJI_SEQUENCE = `${EMOJI_PART}(?:\\u200D${EMOJI_PART})*`;
|
||||
const EMOJI_SEQUENCE_OR_EMPTY_CHARACTER_REGEX = new RegExp(
|
||||
`(${EMOJI_SEQUENCE})|${EMPTY_CHARACTERS.join("|")}`,
|
||||
"gu",
|
||||
);
|
||||
|
||||
const zalgoRe = /%CC%/;
|
||||
export const hasZalgo = (txt: string) => zalgoRe.test(encodeURIComponent(txt));
|
||||
@@ -479,7 +484,12 @@ export const safeNullableStringSchema = ({
|
||||
export function actuallyNonEmptyStringOrNull(value: unknown) {
|
||||
if (typeof value !== "string") return value;
|
||||
|
||||
const trimmed = value.replace(EMPTY_CHARACTERS_REGEX, "").trim();
|
||||
const trimmed = value
|
||||
.replace(
|
||||
EMOJI_SEQUENCE_OR_EMPTY_CHARACTER_REGEX,
|
||||
(_, emojiSequence?: string) => emojiSequence ?? "",
|
||||
)
|
||||
.trim();
|
||||
|
||||
return trimmed === "" ? null : trimmed;
|
||||
}
|
||||
|
||||
4
changelog/2026-10-27-emoji-sequences-kept-in-text.md
Normal file
4
changelog/2026-10-27-emoji-sequences-kept-in-text.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
type: bug
|
||||
---
|
||||
Fixed combined emojis such as 🏳️🌈, 🏳️⚧️ and 👨👩👧 getting split into separate emojis when saved in text fields
|
||||
Reference in New Issue
Block a user