-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Size of the single emoji in chat along with updated Emoji Regex #5039
Changes from 11 commits
f0273ce
41d5ecf
800e002
8fe203d
1da613a
87a29b2
1f6354b
c07557b
cb3a584
c6e1d9a
09a56b5
73655c7
031191e
b3322b6
09babe0
5d75570
22ca1d7
52d9827
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* eslint radix: ["error", "as-needed"] */ | ||
|
||
/** | ||
* getEmojiUnicode | ||
* Get the unicode code of an emoji in base 16. | ||
* | ||
* @name emojiUnicode | ||
* @function | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can make these docs more consistent with the others in our app. Notably, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay noted. |
||
* @param {String} input The emoji character. | ||
* @returns {String} The base 16 unicode code. | ||
*/ | ||
export default function getEmojiUnicode(input) { | ||
if (input.length === 0) { | ||
return ''; | ||
} | ||
|
||
if (input.length === 1) { | ||
return input.charCodeAt(0).toString().split(' ').map(val => parseInt(val).toString(16)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
.join(' '); | ||
} | ||
|
||
const pairs = []; | ||
for (let i = 0; i < input.length; i++) { | ||
if (input.charCodeAt(i) >= 0xd800 && input.charCodeAt(i) <= 0xdbff) { // high surrogate | ||
if (input.charCodeAt(i + 1) >= 0xdc00 && input.charCodeAt(i + 1) <= 0xdfff) { | ||
// low surrogate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is a surrogate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the emojis are stored as two Unicodes. Hence we call each of the Unicode as high surrogate and low surrogate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it thanks. I'm not really familiar with this language - could we maybe add a comment that briefly explains what we mean when we refer to a "surrogate"? |
||
pairs.push( | ||
((input.charCodeAt(i) - 0xd800) * 0x400) | ||
+ (input.charCodeAt(i + 1) - 0xdc00) + 0x10000, | ||
); | ||
} | ||
} else if (input.charCodeAt(i) < 0xd800 || input.charCodeAt(i) > 0xdfff) { | ||
// modifiers and joiners | ||
pairs.push(input.charCodeAt(i)); | ||
} | ||
} | ||
return pairs.map(val => parseInt(val).toString(16)).join(' '); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Function to remove Skin Tone and utf16 surrogates from Emoji | ||
* @param {String} emojiCode | ||
* @returns {String} | ||
*/ | ||
export default function trimEmojiUnicode(emojiCode) { | ||
return emojiCode.replace(/(fe0f|1f3fb|1f3fc|1f3fd|1f3fe|1f3ff)$/, '').trim(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ import moment from 'moment'; | |
import CONST from '../CONST'; | ||
import {showBankAccountFormValidationError, showBankAccountErrorModal} from './actions/BankAccounts'; | ||
import {translateLocal} from './translate'; | ||
import getEmojiUnicode from './Emoji/getEmojiUnicode'; | ||
import trimEmojiUnicode from './Emoji/trimEmojiUnicode'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably these could be combined into a single file called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay noted |
||
|
||
/** | ||
* Validating that this is a valid address (PO boxes are not allowed) | ||
|
@@ -31,7 +33,9 @@ function isSingleEmoji(message) { | |
} | ||
|
||
const matchedEmoji = match[0]; | ||
return message.length === matchedEmoji.length; | ||
const matchedUnicode = getEmojiUnicode(matchedEmoji); | ||
const currentMessageUnicode = trimEmojiUnicode(getEmojiUnicode(message)); | ||
return matchedUnicode === currentMessageUnicode; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay should I move it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That works for me! Thanks! |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import _ from 'underscore'; | ||
import Emoji from '../../assets/emojis'; | ||
import CONST from '../../src/CONST'; | ||
import {isSingleEmoji} from '../../src/libs/ValidationUtils'; | ||
|
||
describe('EmojiRegexTest', () => { | ||
it('matches all the emojis in the list', () => { | ||
const emojiMatched = _.every(Emoji, (emoji) => { | ||
if (emoji.header === true || emoji.code === CONST.EMOJI_SPACER) { | ||
return true; | ||
} | ||
const isEmojiMatched = isSingleEmoji(emoji.code); | ||
let skinToneMatched = true; | ||
if (emoji.types) { | ||
skinToneMatched = _.every(emoji.types, emojiWithSkinTone => isSingleEmoji(emojiWithSkinTone)); | ||
} | ||
return skinToneMatched && isEmojiMatched; | ||
}); | ||
|
||
expect(emojiMatched).toBe(true); | ||
}); | ||
|
||
it('matches single emojis variants for size', () => { | ||
expect(isSingleEmoji('👨👩👦️')).toBe(true); | ||
expect(isSingleEmoji('👉')).toBe(true); | ||
expect(isSingleEmoji('👊🏾')).toBe(true); | ||
expect(isSingleEmoji('😪️')).toBe(true); | ||
expect(isSingleEmoji('❤️')).toBe(true); | ||
expect(isSingleEmoji('👨👩👦️')).toBe(true); | ||
expect(isSingleEmoji('😎️')).toBe(true); | ||
expect(isSingleEmoji('🔫️')).toBe(true); | ||
expect(isSingleEmoji('🛍')).toBe(true); | ||
expect(isSingleEmoji('⁉️')).toBe(true); | ||
expect(isSingleEmoji('*️⃣')).toBe(true); | ||
expect(isSingleEmoji('✳️')).toBe(true); | ||
expect(isSingleEmoji('👶🏽')).toBe(true); | ||
expect(isSingleEmoji('🕍')).toBe(true); | ||
expect(isSingleEmoji('🇺🇲')).toBe(true); | ||
expect(isSingleEmoji('🇮🇳')).toBe(true); | ||
expect(isSingleEmoji('🇺🇦️')).toBe(true); | ||
marcaaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we silencing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt
also accepts a second paramradix
, which I've markedas-needed
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just add the radix?