Skip to content

Commit

Permalink
Fix support for emoji with unneeded vs16
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 13, 2020
1 parent 3e1bb22 commit 85d3803
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var own = {}.hasOwnProperty

var type = 'EmoticonNode'

var vs16 = 0xfe0f

// Map of visitors.
var fns = {
encode: toEmoji,
Expand Down Expand Up @@ -78,9 +80,19 @@ function emoji(options) {

// Map a value to an emoji.
function parse(value) {
var without

if (own.call(emoji2info, value)) return value
if (own.call(emoticon2emoji, value)) return emoticon2emoji[value]
if (own.call(gemoji2emoji, value)) return gemoji2emoji[value]

if (value.charCodeAt(value.length - 1) === vs16) {
without = value.slice(0, -1)
/* istanbul ignore else - pretty weird to have something that parses as an
* emoji, with a superfluous fe0f, and not have it exist, but hey, better
* to be sure. */
if (own.call(emoji2info, without)) return without
}
}

// Change to a GitHub emoji short-code.
Expand Down
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ test('emoji', function (t) {
)
})

retext()
.use(emoji, {convert: 'decode'})
.process('Zap! ⚡️', function (err, file) {
t.deepEqual(
[err, String(file)],
[null, 'Zap! :zap:'],
'should support a superfluous variant selector 16'
)
})

function data() {
return transformer
function transformer(node) {
Expand Down

0 comments on commit 85d3803

Please sign in to comment.