1
0
mirror of https://github.com/twitter/twemoji.git synced 2024-10-02 21:02:03 +00:00

Add parse handling for stray/unnecessary VS16s

This commit is contained in:
Nathan Downs 2018-07-10 11:29:36 -07:00
parent 1bbd06079e
commit c9a665abb2
6 changed files with 38 additions and 10 deletions

View File

@ -836,7 +836,7 @@ function createTwemoji(re) {
iconId = grabTheRightIcon(rawText);
i = index + rawText.length;
src = options.callback(iconId, options);
if (src) {
if (iconId && src) {
img = new Image();
img.onerror = options.onerror;
img.setAttribute('draggable', 'false');
@ -897,7 +897,7 @@ function createTwemoji(re) {
src = options.callback(iconId, options),
attrib,
attrname;
if (src) {
if (iconId && src) {
// recycle the match string replacing the emoji
// with its image counter part
ret = '<img '.concat(

View File

@ -534,7 +534,35 @@ wru.test([{
div.firstChild.src === 'https://twemoji.maxcdn.com/2/72x72/2639.png'
);
}
}, {
},{
name: 'lone vs16s',
test: function () {
wru.assert('are not parsed in strings',
twemoji.parse('\ufe0f') === '\ufe0f'
);
var div = document.createElement('div');
div.innerHTML = '\ufe0f';
twemoji.parse(div);
wru.assert('are not parsed in nodes',
div.innerHTML === '\ufe0f'
);
}
},{
name: 'unnecessary vs16s',
test: function () {
wru.assert('are not parsed in strings',
twemoji.parse('\ud83d\ude10\ufe0f') === '<img class="emoji" draggable="false" alt="\ud83d\ude10" src="https://twemoji.maxcdn.com/2/72x72/1f610.png"/>\ufe0f'
);
var div = document.createElement('div');
div.innerHTML = '\ud83d\ude10\ufe0f';
twemoji.parse(div);
wru.assert('are not parsed in nodes',
div.children.length === 1 && div.innerText === '\ufe0f'
);
}
},{
name: 'multiple parsing using a callback',
test: function () {
wru.assert(

View File

@ -374,7 +374,7 @@ define(function () {
iconId = grabTheRightIcon(rawText);
i = index + rawText.length;
src = options.callback(iconId, options);
if (src) {
if (iconId && src) {
img = new Image();
img.onerror = options.onerror;
img.setAttribute('draggable', 'false');
@ -435,7 +435,7 @@ define(function () {
src = options.callback(iconId, options),
attrib,
attrname;
if (src) {
if (iconId && src) {
// recycle the match string replacing the emoji
// with its image counter part
ret = '<img '.concat(

View File

@ -373,7 +373,7 @@ var twemoji = (function (
iconId = grabTheRightIcon(rawText);
i = index + rawText.length;
src = options.callback(iconId, options);
if (src) {
if (iconId && src) {
img = new Image();
img.onerror = options.onerror;
img.setAttribute('draggable', 'false');
@ -434,7 +434,7 @@ var twemoji = (function (
src = options.callback(iconId, options),
attrib,
attrname;
if (src) {
if (iconId && src) {
// recycle the match string replacing the emoji
// with its image counter part
ret = '<img '.concat(

2
2/twemoji.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -374,7 +374,7 @@ var twemoji = (function (
iconId = grabTheRightIcon(rawText);
i = index + rawText.length;
src = options.callback(iconId, options);
if (src) {
if (iconId && src) {
img = new Image();
img.onerror = options.onerror;
img.setAttribute('draggable', 'false');
@ -435,7 +435,7 @@ var twemoji = (function (
src = options.callback(iconId, options),
attrib,
attrname;
if (src) {
if (iconId && src) {
// recycle the match string replacing the emoji
// with its image counter part
ret = '<img '.concat(