fix(emojos): actually fix trademark character (#693)

another fix for #679
This commit is contained in:
Nolan Lawson 2018-11-25 12:35:52 -08:00 committed by GitHub
parent 41d7e40662
commit 9c74a072bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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)

View File

@ -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("<p>It's shapes™ ... continued</p>", replacer),
"<p>It's shapes™ ... continued</p>"
)
})
it('does not replace emoji inside HTML tags', function () {