diff --git a/client/js/helpers/parse.js b/client/js/helpers/parse.js index 61a388a1..6663827b 100644 --- a/client/js/helpers/parse.js +++ b/client/js/helpers/parse.js @@ -12,7 +12,7 @@ import LinkPreviewFileSize from "../../components/LinkPreviewFileSize.vue"; import InlineChannel from "../../components/InlineChannel.vue"; import Username from "../../components/Username.vue"; -const emojiModifiersRegex = /[\u{1f3fb}-\u{1f3ff}]/gu; +const emojiModifiersRegex = /[\u{1f3fb}-\u{1f3ff}]|\u{fe0f}/gu; // Create an HTML `span` with styling information for a given fragment function createFragment(fragment, createElement) { diff --git a/scripts/generate-emoji.js b/scripts/generate-emoji.js index d864d074..715a3ac0 100644 --- a/scripts/generate-emoji.js +++ b/scripts/generate-emoji.js @@ -4,6 +4,9 @@ const got = require("got"); const path = require("path"); const fs = require("fs"); +// same regex as found in client/../parse.js +const emojiModifiersRegex = /[\u{1f3fb}-\u{1f3ff}]|\u{fe0f}/gu; + (async () => { const response = await got( "https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json" @@ -13,7 +16,8 @@ const fs = require("fs"); const fullNameEmojiMap = {}; for (const emoji of emojiStrategy) { - fullNameEmojiMap[emoji.emoji] = emoji.description; + const cleanEmoji = emoji.emoji.replace(emojiModifiersRegex, ""); + fullNameEmojiMap[cleanEmoji] = emoji.description; for (const alias of emoji.aliases) { emojiMap[alias] = emoji.emoji; diff --git a/test/client/js/helpers/parse.js b/test/client/js/helpers/parse.js index 9cdce2b8..70272cd1 100644 --- a/test/client/js/helpers/parse.js +++ b/test/client/js/helpers/parse.js @@ -458,6 +458,22 @@ describe("IRC formatted message parser", () => { expected: '🤷‍♀️', }, + { + name: "with emoji variant selector", + input: "\u{2695}\u{FE0F}", + expected: + '\u{2695}\u{FE0F}', + }, + { + name: "with text variant selector", + input: "\u{2695}\u{FE0E}", + expected: "\u{2695}\u{FE0E}", // this does not match because FE0E is specifically a text variant + }, + { + name: "without variant selector", + input: "\u{2695}", + expected: "\u{2695}", // this does not match because emoji-regex expects \uFE0F as per the emoji specification + }, { // FIXME: These multiple `span`s should be optimized into a single one. See https://github.com/thelounge/thelounge/issues/1783 name: "wrapped in style",