From e39c3298d6fed420dfcf768dce25792608bf132a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 29 Jun 2019 07:28:09 +0100 Subject: [PATCH 1/3] Emojibase data includes blank variations, accept these when scanning Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/HtmlUtils.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/HtmlUtils.js b/src/HtmlUtils.js index 6cd06678ea..3777ffe46b 100644 --- a/src/HtmlUtils.js +++ b/src/HtmlUtils.js @@ -1,6 +1,7 @@ /* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017, 2018 New Vector Ltd +Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,7 +27,6 @@ import * as linkify from 'linkifyjs'; import linkifyMatrix from './linkify-matrix'; import _linkifyElement from 'linkifyjs/element'; import _linkifyString from 'linkifyjs/string'; -import escape from 'lodash/escape'; import classNames from 'classnames'; import MatrixClientPeg from './MatrixClientPeg'; import url from 'url'; @@ -57,6 +57,8 @@ const COLOR_REGEX = /^#[0-9a-fA-F]{6}$/; const PERMITTED_URL_SCHEMES = ['http', 'https', 'ftp', 'mailto', 'magnet']; +const VARIATION_SELECTOR = String.fromCharCode(0xFE0F); + /* * Return true if the given string contains emoji * Uses a much, much simpler regex than emojibase's so will give false @@ -77,6 +79,7 @@ export function isSingleEmoji(str) { return mightContainEmoji(str) && SINGLE_EMOJI_REGEX.test(str); } + /** * Returns the shortcode for an emoji character. * @@ -84,7 +87,8 @@ export function isSingleEmoji(str) { * @return {String} The shortcode (such as :thumbup:) */ export function unicodeToShortcode(char) { - const data = EMOJIBASE.find(e => e.unicode === char); + const emptyVariation = char + VARIATION_SELECTOR; + const data = EMOJIBASE.find(e => e.unicode === char || e.unicode === emptyVariation); return (data && data.shortcodes ? `:${data.shortcodes[0]}:` : ''); } From d0c8e095320604f41e9a0626bc11cdb769449d14 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 29 Jun 2019 07:30:16 +0100 Subject: [PATCH 2/3] delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/HtmlUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/HtmlUtils.js b/src/HtmlUtils.js index 3777ffe46b..16c84deedd 100644 --- a/src/HtmlUtils.js +++ b/src/HtmlUtils.js @@ -79,7 +79,6 @@ export function isSingleEmoji(str) { return mightContainEmoji(str) && SINGLE_EMOJI_REGEX.test(str); } - /** * Returns the shortcode for an emoji character. * From ecc672cccc90dfb3f1dca95d8ee0f80d2ce1bc01 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 5 Jul 2019 08:40:00 +0100 Subject: [PATCH 3/3] add comment Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/HtmlUtils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/HtmlUtils.js b/src/HtmlUtils.js index 16c84deedd..73ab28e65c 100644 --- a/src/HtmlUtils.js +++ b/src/HtmlUtils.js @@ -86,6 +86,8 @@ export function isSingleEmoji(str) { * @return {String} The shortcode (such as :thumbup:) */ export function unicodeToShortcode(char) { + // Check against both the char and the char with an empty variation selector appended because that's how + // emoji-base stores its base emojis which have variations. https://github.com/vector-im/riot-web/issues/9785 const emptyVariation = char + VARIATION_SELECTOR; const data = EMOJIBASE.find(e => e.unicode === char || e.unicode === emptyVariation); return (data && data.shortcodes ? `:${data.shortcodes[0]}:` : '');