Skip to content

Commit

Permalink
Update search for colon-syntax emoji to ignore case (#3443)
Browse files Browse the repository at this point in the history
* Add tests for existing replaceColons functionality

* Update to lowercase before matching short names

* Update lib_test.ts
  • Loading branch information
backspace authored and kenpowers-signal committed Jul 8, 2019
1 parent cb27211 commit f2dd10c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions ts/components/emoji/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
30 changes: 30 additions & 0 deletions ts/test/components/emoji/lib_test.ts
Original file line number Diff line number Diff line change
@@ -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 😀');
});
});

0 comments on commit f2dd10c

Please sign in to comment.