Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-16 03:15:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-16 03:15:50 +0300
commite04431d29efaf17dda9dfbfbd0c5001693b25ee4 (patch)
treef114abad1f4882ef6c9c702e8de3a84334809031 /app/assets/javascripts/emoji
parent1c898dc5c10bbedf94386d917259153d73608495 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/emoji')
-rw-r--r--app/assets/javascripts/emoji/constants.js3
-rw-r--r--app/assets/javascripts/emoji/index.js27
2 files changed, 21 insertions, 9 deletions
diff --git a/app/assets/javascripts/emoji/constants.js b/app/assets/javascripts/emoji/constants.js
index e9f2272e759..a6eb4256561 100644
--- a/app/assets/javascripts/emoji/constants.js
+++ b/app/assets/javascripts/emoji/constants.js
@@ -16,3 +16,6 @@ export const CATEGORY_ICON_MAP = {
export const EMOJIS_PER_ROW = 9;
export const EMOJI_ROW_HEIGHT = 34;
export const CATEGORY_ROW_HEIGHT = 37;
+
+export const CACHE_VERSION_KEY = 'gl-emoji-map-version';
+export const CACHE_KEY = 'gl-emoji-map';
diff --git a/app/assets/javascripts/emoji/index.js b/app/assets/javascripts/emoji/index.js
index c0f2153ce5b..b507792cc91 100644
--- a/app/assets/javascripts/emoji/index.js
+++ b/app/assets/javascripts/emoji/index.js
@@ -1,9 +1,9 @@
import { escape, minBy } from 'lodash';
+import emojiRegexFactory from 'emoji-regex';
import emojiAliases from 'emojis/aliases.json';
-import { sanitize } from '~/lib/dompurify';
import AccessorUtilities from '../lib/utils/accessor';
import axios from '../lib/utils/axios_utils';
-import { CATEGORY_ICON_MAP, FREQUENTLY_USED_KEY } from './constants';
+import { CACHE_KEY, CACHE_VERSION_KEY, CATEGORY_ICON_MAP, FREQUENTLY_USED_KEY } from './constants';
let emojiMap = null;
let validEmojiNames = null;
@@ -17,10 +17,15 @@ const isLocalStorageAvailable = AccessorUtilities.canUseLocalStorage();
async function loadEmoji() {
if (
isLocalStorageAvailable &&
- window.localStorage.getItem('gl-emoji-map-version') === EMOJI_VERSION &&
- window.localStorage.getItem('gl-emoji-map')
+ window.localStorage.getItem(CACHE_VERSION_KEY) === EMOJI_VERSION &&
+ window.localStorage.getItem(CACHE_KEY)
) {
- return JSON.parse(window.localStorage.getItem('gl-emoji-map'));
+ const emojis = JSON.parse(window.localStorage.getItem(CACHE_KEY));
+ // Workaround because the pride flag is broken in EMOJI_VERSION = '1'
+ if (emojis.gay_pride_flag) {
+ emojis.gay_pride_flag.e = '🏳️‍🌈';
+ }
+ return emojis;
}
// We load the JSON file direct from the server
@@ -29,15 +34,19 @@ async function loadEmoji() {
const { data } = await axios.get(
`${gon.relative_url_root || ''}/-/emojis/${EMOJI_VERSION}/emojis.json`,
);
- window.localStorage.setItem('gl-emoji-map-version', EMOJI_VERSION);
- window.localStorage.setItem('gl-emoji-map', JSON.stringify(data));
+ window.localStorage.setItem(CACHE_VERSION_KEY, EMOJI_VERSION);
+ window.localStorage.setItem(CACHE_KEY, JSON.stringify(data));
return data;
}
async function loadEmojiWithNames() {
- return Object.entries(await loadEmoji()).reduce((acc, [key, value]) => {
- acc[key] = { ...value, name: key, e: sanitize(value.e) };
+ const emojiRegex = emojiRegexFactory();
+ return Object.entries(await loadEmoji()).reduce((acc, [key, value]) => {
+ // Filter out entries which aren't emojis
+ if (value.e.match(emojiRegex)?.[0] === value.e) {
+ acc[key] = { ...value, name: key };
+ }
return acc;
}, {});
}