fix(emoji): asterisk should not be treated as emoji (#668)

This commit is contained in:
Nolan Lawson 2018-11-20 22:41:41 -08:00 committed by GitHub
parent 35a42c9fd3
commit 3dae883761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

2
package-lock.json generated
View File

@ -508,7 +508,7 @@
}, },
"util": { "util": {
"version": "0.10.3", "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=", "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=",
"requires": { "requires": {
"inherits": "2.0.1" "inherits": "2.0.1"

View File

@ -9,7 +9,7 @@ export function replaceEmoji (string, replacer) {
function safeReplacer (substring) { function safeReplacer (substring) {
// emoji regex matches digits and pound sign https://git.io/fpl6J // emoji regex matches digits and pound sign https://git.io/fpl6J
if (substring.match(/^[0-9#]+$/)) { if (substring.match(/^[0-9#*]+$/)) {
return substring return substring
} }
return replacer(substring) return replacer(substring)

View File

@ -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 = _ => `<div>${_}</div>` let replacer = _ => `<div>${_}</div>`
assert.strictEqual( assert.strictEqual(
replaceEmoji(`it's over #9000`, replacer), replaceEmoji(`it's over #9000`, replacer),
`it's over #9000` `it's over #9000`
) )
assert.strictEqual(
replaceEmoji(`woot !@#$%^&*()~` + '`' + `{[}]:;"'<,>.?/£`, replacer),
`woot !@#$%^&*()~` + '`' + `{[}]:;"'<,>.?/£`
)
}) })
it('does not replace emoji inside HTML tags', function () { it('does not replace emoji inside HTML tags', function () {