Skip to content

fix: convert all emoji shortnames in a message, not just the last#1316

Open
yash113gadia wants to merge 1 commit into
RocketChat:developfrom
yash113gadia:fix/parseemoji-multiple-shortnames
Open

fix: convert all emoji shortnames in a message, not just the last#1316
yash113gadia wants to merge 1 commit into
RocketChat:developfrom
yash113gadia:fix/parseemoji-multiple-shortnames

Conversation

@yash113gadia
Copy link
Copy Markdown

Closes #1315

Problem

parseEmoji collected every :shortname: match but then picked only the last one and ran a single String.replace, which swaps the first occurrence of that match. As a result a message with multiple shortnames left all but one as raw text:

  • ":smile: and :heart:"":smile: and ❤️" (first emoji not converted)
  • ":tada: foo :tada:""🎉 foo :tada:" (wrong occurrence converted)

Most visible on pasted text and on attachment captions (AttachmentPreview parses the whole description once on submit). Incremental typing masked it because each shortname was converted as it completed.

Fix

emoji-toolkit's shortnameToUnicode() already converts every shortname in a string and leaves unknown shortnames and plain text untouched, so the hand-rolled match/replace is both buggy and unnecessary:

export const parseEmoji = (text) => emojione.shortnameToUnicode(text);

Verification

Checked against emoji-toolkit@9.0.1 (the version this package depends on):

Input Before After
:smile: and :heart: :smile: and ❤️ 😄 and ❤️
:tada: foo :tada: 🎉 foo :tada: 🎉 foo 🎉
:not_real_xyz: :smile: :not_real_xyz: 😄 :not_real_xyz: 😄
no emoji here unchanged unchanged

Plain text and unknown shortnames are preserved.

parseEmoji only ever converted a single shortname: it collected every
`:shortname:` match but then picked the last one and ran a single
`String.replace`, which swaps the first occurrence of that match. So a
message with multiple shortnames left all but one as raw text, e.g.
":smile: and :heart:" rendered as ":smile: and ❤️", and
":tada: foo :tada:" converted the wrong occurrence.

This is most visible on pasted text and on attachment captions
(AttachmentPreview parses the whole description once on submit), since
incremental typing happened to convert each shortname as it completed.

emoji-toolkit's shortnameToUnicode already converts every shortname in a
string and leaves unknown shortnames and plain text untouched, so the
hand-rolled match/replace is both buggy and unnecessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant