Description
parseEmoji (packages/react/src/lib/emoji.js) only ever converts a single emoji shortname in a given text. It collects every :shortname: match with a global regex but then picks the last match and runs one String.replace, which replaces the first occurrence of that match string:
export const parseEmoji = (text) => {
const regx = /:([^:]*):/g;
const regx_data = text.match(regx);
if (regx_data) {
const result = regx_data[regx_data.length - 1];
const d = emojione.shortnameToUnicode(result);
if (d !== undefined) text = text.replace(result, d);
}
return text;
};
So any text containing more than one shortname is rendered incorrectly.
Steps to reproduce
- In the message box, paste
:smile: and :heart: (paste, so it arrives in one change rather than being typed char-by-char).
- Or send a file with an attachment caption containing two shortnames (the caption is parsed once on submit in
AttachmentPreview).
Expected
Both shortnames convert: 😄 and ❤️
Actual
Only the last converts and the first is left as raw text: :smile: and ❤️. With a repeated shortname like :tada: foo :tada:, the first occurrence is converted and the second is left literal (🎉 foo :tada:).
Notes
Incremental typing usually hides this because each shortname is converted as it's completed, but pasting and attachment captions both pass a full multi-shortname string in one call.
emoji-toolkit's shortnameToUnicode() already converts every shortname in a string and leaves unknown shortnames / plain text untouched, so the hand-rolled match/replace is both buggy and unnecessary.
Description
parseEmoji(packages/react/src/lib/emoji.js) only ever converts a single emoji shortname in a given text. It collects every:shortname:match with a global regex but then picks the last match and runs oneString.replace, which replaces the first occurrence of that match string:So any text containing more than one shortname is rendered incorrectly.
Steps to reproduce
:smile: and :heart:(paste, so it arrives in one change rather than being typed char-by-char).AttachmentPreview).Expected
Both shortnames convert:
😄 and ❤️Actual
Only the last converts and the first is left as raw text:
:smile: and ❤️. With a repeated shortname like:tada: foo :tada:, the first occurrence is converted and the second is left literal (🎉 foo :tada:).Notes
Incremental typing usually hides this because each shortname is converted as it's completed, but pasting and attachment captions both pass a full multi-shortname string in one call.
emoji-toolkit'sshortnameToUnicode()already converts every shortname in a string and leaves unknown shortnames / plain text untouched, so the hand-rolled match/replace is both buggy and unnecessary.