mirror of
https://github.com/nolanlawson/pinafore
synced 2024-12-12 02:07:26 +01:00
fix(emojos): actually fix trademark character (#693)
another fix for #679
This commit is contained in:
parent
41d7e40662
commit
9c74a072bf
@ -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)
|
||||
|
@ -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 () {
|
||||
|
Loading…
Reference in New Issue
Block a user