Skip to content

Only the last emoji shortname in a message is converted to unicode #1315

Description

@yash113gadia

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

  1. In the message box, paste :smile: and :heart: (paste, so it arrives in one change rather than being typed char-by-char).
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions