Fix: trying to use emojis with an uppercase letter breaks the message field #3560
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previoux fix (#3501) was wrong and introduced other issues:
So, the correct fix is just to remove the 'i' modifier for the shortname_regex, to always have case sensitive emojis.
More details about this PR
Before my previous fix (#3501), emojis were broken if you tried to call them without beeing case sensitive.
Consider we have a ":abc:" short_name.
The shortname_regex was case insensitive, so it detected for example ":ABC:". But then, the following line was broken:
converse.js/src/headless/plugins/emoji/utils.js
Line 102 in f8935e0
by_sn[ref[0]]
was undefined, and the.cp
make it fail.Same here:
converse.js/src/headless/plugins/emoji/utils.js
Line 176 in f8935e0
text === refs[0]['shortname']
is case sensitive.So, i added the
text.toLowerCase()
... But this is assuming that shortnames are lowercase... When you deal with custom emojis, nothing tells you have to use lowerCase.(And
.toLowerCase()
may be inexact for some alphabets).Moreover, this was fixing the message sending... But the message display was broken. There was a missing
toLowerCase()
here:converse.js/src/shared/chat/utils.js
Line 222 in 8754f03
To resume:
Trying to handle case insensivity would be difficult... And could cause some troubles if there are multiple emojis with are equals when case insensitive... (in the JSON object, you can have ":ABC" and ":abc"...).
So i think it is better to make shortnames case sensitive. In most case, it will just work.
(the only code part that was trying to make emojis shortnames case insensitive is the
i
modifier on the regex this PR changes)The only issue i can see, is if you have some custom emoji without the ":" prefix, and when you use a mobile phone that will automatically use an uppercase for the first letter of a new sentence. This seems a reasonable assumption.