From 9c74a072bfbea26ccb523c9a7fd70d3c3fb00e68 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 25 Nov 2018 12:35:52 -0800 Subject: [PATCH] fix(emojos): actually fix trademark character (#693) another fix for #679 --- routes/_utils/replaceEmoji.js | 5 ++++- tests/unit/test-emoji.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/routes/_utils/replaceEmoji.js b/routes/_utils/replaceEmoji.js index 1abdf42e..8b6b811e 100644 --- a/routes/_utils/replaceEmoji.js +++ b/routes/_utils/replaceEmoji.js @@ -1,5 +1,8 @@ import { getEmojiRegex } from './emojiRegex' +// \ufe0f is a variation selector, which seems to appear for some reason in e.g. ™ +let NON_EMOJI_REGEX = new RegExp('^[0-9#*™®\ufe0f]+$') + // replace emoji in HTML with something else, safely skipping HTML tags export function replaceEmoji (string, replacer) { let output = '' @@ -9,7 +12,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(NON_EMOJI_REGEX)) { return substring } return replacer(substring) diff --git a/tests/unit/test-emoji.js b/tests/unit/test-emoji.js index 8da04b2c..c1d3c5df 100644 --- a/tests/unit/test-emoji.js +++ b/tests/unit/test-emoji.js @@ -70,6 +70,17 @@ describe('test-emoji.js', function () { replaceEmoji(`woot !@#$%^&*()~` + '`' + `{[}]:;"'<,>.?/£™℠®`, replacer), `woot !@#$%^&*()~` + '`' + `{[}]:;"'<,>.?/£™℠®` ) + + assert.strictEqual( + replaceEmoji(`woot !@#$%^&*()~` + '`' + `{[}]:;"'<,>.?/£™℠®`, replacer), + `woot !@#$%^&*()~` + '`' + `{[}]:;"'<,>.?/£™℠®` + ) + + // hidden VARIATION SELECTOR character is in here + assert.strictEqual( + replaceEmoji("

It's shapes™️ ... continued

", replacer), + "

It's shapes™️ ... continued

" + ) }) it('does not replace emoji inside HTML tags', function () {