]> cat aescling's git repositories - mastodon.git/commitdiff
Skip VS15 (Emoji textual presentation). (#8553)
authorM Somerville <dracos@users.noreply.github.com>
Sat, 1 Sep 2018 17:42:02 +0000 (18:42 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Sat, 1 Sep 2018 17:42:02 +0000 (19:42 +0200)
Mastodon converts all Emoji to images, whether they have a VS15 after
them or not, but leaves the VS15 in the string, which is displayed as
a black box in Safari.

app/javascript/mastodon/features/emoji/__tests__/emoji-test.js
app/javascript/mastodon/features/emoji/emoji.js

index d91b4849754e1c54715d2ad32b9eb871c86bbda0..c8425c4c6db63e3a0fd2de969daf8a090179f465 100644 (file)
@@ -73,5 +73,10 @@ describe('emoji', () => {
       expect(emojify('<span class="invisible">😄<br/>😴</span>😇'))
         .toEqual('<span class="invisible">😄<br/>😴</span><img draggable="false" class="emojione" alt="😇" title=":innocent:" src="/emoji/1f607.svg" />');
     });
+
+    it('skips the textual presentation VS15 character', () => {
+      expect(emojify('✴︎')) // This is U+2734 EIGHT POINTED BLACK STAR then U+FE0E VARIATION SELECTOR-15
+        .toEqual('<img draggable="false" class="emojione" alt="✴" title=":eight_pointed_black_star:" src="/emoji/2734.svg" />');
+    });
   });
 });
index 0f005dd5040d130f893da285831b1ab29dd7eee1..988cea2530d1e6f7a9b799dc4c3141343eba3583 100644 (file)
@@ -62,6 +62,10 @@ const emojify = (str, customEmojis = {}) => {
       const title = shortCode ? `:${shortCode}:` : '';
       replacement = `<img draggable="false" class="emojione" alt="${match}" title="${title}" src="${assetHost}/emoji/${filename}.svg" />`;
       rend = i + match.length;
+      // If the matched character was followed by VS15 (for selecting text presentation), skip it.
+      if (str.codePointAt(rend) === 65038) {
+        rend += 1;
+      }
     }
     rtn += str.slice(0, i) + replacement;
     str = str.slice(rend);