Skip to content

Commit

Permalink
Fix: trying to use emojis with an uppercase letter breaks the message…
Browse files Browse the repository at this point in the history
… field.

Previoux fix (conversejs#3501) was
wrong and introduced other issues:
* impossible to define an emoji with uppercase letters
* possible to use an emoji 🔤 by using :Abc:, but it won't display

So, the correct fix is just to remove the 'i' modifier for the
shortname_regex, to always have case sensitive emojis.
  • Loading branch information
JohnXLivingston committed Dec 5, 2024
1 parent 61d4683 commit 2918321
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/headless/plugins/emoji/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const emojis = {
converse.emojis.shortnames = converse.emojis.list.map((m) => m.sn);
const getShortNames = () =>
converse.emojis.shortnames.map((s) => s.replace(/[+]/g, '\\$&')).join('|');
converse.emojis.shortnames_regex = new RegExp(getShortNames(), 'gi');
converse.emojis.shortnames_regex = new RegExp(getShortNames(), 'g');
converse.emojis.initialized_promise.resolve();
}
return converse.emojis.initialized_promise;
Expand Down
4 changes: 2 additions & 2 deletions src/headless/plugins/emoji/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function getShortnameReferences (text) {
}
const references = [...text.matchAll(converse.emojis.shortnames_regex)].filter(ref => ref[0].length > 0);
return references.map(ref => {
const cp = converse.emojis.by_sn[ref[0].toLowerCase()].cp;
const cp = converse.emojis.by_sn[ref[0]].cp;
return {
cp,
'begin': ref.index,
Expand Down Expand Up @@ -190,7 +190,7 @@ export function isOnlyEmojis (text) {
}
const emojis = words.filter(text => {
const refs = getCodePointReferences(u.shortnamesToUnicode(text));
return refs.length === 1 && (text.toLowerCase() === refs[0]['shortname'] || text === refs[0]['emoji']);
return refs.length === 1 && (text === refs[0]['shortname'] || text === refs[0]['emoji']);
});
return emojis.length === words.length;
}
Expand Down

0 comments on commit 2918321

Please sign in to comment.