From 3dae88376130108dc5e74ba42fe86e629a325be2 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 20 Nov 2018 22:41:41 -0800 Subject: [PATCH] fix(emoji): asterisk should not be treated as emoji (#668) --- package-lock.json | 2 +- routes/_utils/replaceEmoji.js | 2 +- tests/unit/test-emoji.js | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 85b9015..867093a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -508,7 +508,7 @@ }, "util": { "version": "0.10.3", - "resolved": "http://registry.npmjs.org/util/-/util-0.10.3.tgz", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", "requires": { "inherits": "2.0.1" diff --git a/routes/_utils/replaceEmoji.js b/routes/_utils/replaceEmoji.js index 12df946..b27f3c0 100644 --- a/routes/_utils/replaceEmoji.js +++ b/routes/_utils/replaceEmoji.js @@ -9,7 +9,7 @@ export function replaceEmoji (string, replacer) { function safeReplacer (substring) { // emoji regex matches digits and pound sign https://git.io/fpl6J - if (substring.match(/^[0-9#]+$/)) { + if (substring.match(/^[0-9#*]+$/)) { return substring } return replacer(substring) diff --git a/tests/unit/test-emoji.js b/tests/unit/test-emoji.js index fc7152b..d827120 100644 --- a/tests/unit/test-emoji.js +++ b/tests/unit/test-emoji.js @@ -60,12 +60,16 @@ describe('test-emoji.js', function () { ) }) - it('does not replace digits or pound', function () { + it('does not replace non-emoji characters', function () { let replacer = _ => `
${_}
` assert.strictEqual( replaceEmoji(`it's over #9000`, replacer), `it's over #9000` ) + assert.strictEqual( + replaceEmoji(`woot !@#$%^&*()~` + '`' + `{[}]:;"'<,>.?/£`, replacer), + `woot !@#$%^&*()~` + '`' + `{[}]:;"'<,>.?/£` + ) }) it('does not replace emoji inside HTML tags', function () {