From f2dd10cd1a2665b96651397785b63c3e9ad5a64a Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Mon, 8 Jul 2019 15:38:25 -0500 Subject: [PATCH] Update search for colon-syntax emoji to ignore case (#3443) * Add tests for existing replaceColons functionality * Update to lowercase before matching short names * Update lib_test.ts --- ts/components/emoji/lib.ts | 1 + ts/test/components/emoji/lib_test.ts | 30 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 ts/test/components/emoji/lib_test.ts diff --git a/ts/components/emoji/lib.ts b/ts/components/emoji/lib.ts index 388e90beb80b..007dd69005d6 100644 --- a/ts/components/emoji/lib.ts +++ b/ts/components/emoji/lib.ts @@ -255,6 +255,7 @@ export function replaceColons(str: string) { return str.replace(/:[a-z0-9-_+]+:(?::skin-tone-[1-5]:)?/gi, m => { const [shortName = '', skinTone = '0'] = m .replace('skin-tone-', '') + .toLowerCase() .split(':') .filter(Boolean); diff --git a/ts/test/components/emoji/lib_test.ts b/ts/test/components/emoji/lib_test.ts new file mode 100644 index 000000000000..22266bc0d8d7 --- /dev/null +++ b/ts/test/components/emoji/lib_test.ts @@ -0,0 +1,30 @@ +import { assert } from 'chai'; + +import { replaceColons } from '../../../components/emoji/lib'; + +describe('replaceColons', () => { + it('replaces known emoji short names between colons', () => { + const anEmoji = replaceColons('hello :grinning:'); + assert.equal(anEmoji, 'hello 😀'); + }); + + it('understands skin tone modifiers', () => { + const skinToneModifierEmoji = replaceColons('hello :wave::skin-tone-5:!'); + assert.equal(skinToneModifierEmoji, 'hello 👋🏿!'); + }); + + it('passes through strings with no colons', () => { + const noEmoji = replaceColons('hello'); + assert.equal(noEmoji, 'hello'); + }); + + it('ignores unknown emoji', () => { + const unknownEmoji = replaceColons(':Unknown: :unknown:'); + assert.equal(unknownEmoji, ':Unknown: :unknown:'); + }); + + it('converts short names to lowercase before matching them', () => { + const emojiWithCaps = replaceColons('hello :Grinning:'); + assert.equal(emojiWithCaps, 'hello 😀'); + }); +});