From d9e79daa6af9634a6892123ae6f4ddd822fa1287 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Tue, 20 Nov 2018 09:42:49 -0800 Subject: [PATCH] fix(emoji): emoji replacer should ignore pound sign (#666) * fix(emoji): emoji replacer should ignore pound sign * add test * fix regex --- routes/_utils/replaceEmoji.js | 3 ++- tests/unit/test-emoji.js | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/routes/_utils/replaceEmoji.js b/routes/_utils/replaceEmoji.js index a76df3f..12df946 100644 --- a/routes/_utils/replaceEmoji.js +++ b/routes/_utils/replaceEmoji.js @@ -8,7 +8,8 @@ export function replaceEmoji (string, replacer) { let emojiRegex = getEmojiRegex() function safeReplacer (substring) { - if (substring.match(/^[0-9]+$/)) { // for some reason, emoji-regex matches digits + // emoji regex matches digits and pound sign https://git.io/fpl6J + 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 3d6a35f..fc7152b 100644 --- a/tests/unit/test-emoji.js +++ b/tests/unit/test-emoji.js @@ -60,11 +60,11 @@ describe('test-emoji.js', function () { ) }) - it('does not replace digits', function () { + it('does not replace digits or pound', function () { let replacer = _ => `
${_}
` assert.strictEqual( - replaceEmoji(`it's over 9000`, replacer), - `it's over 9000` + replaceEmoji(`it's over #9000`, replacer), + `it's over #9000` ) })