Bläddra i källkod

Ignore case when translating shortcodes (#953)

Danilo Bargen 5 år sedan
förälder
incheckning
8cdfff7ec8
2 ändrade filer med 9 tillägg och 1 borttagningar
  1. 5 1
      src/helpers/emoji.ts
  2. 4 0
      tests/ts/emoji_helpers.ts

+ 5 - 1
src/helpers/emoji.ts

@@ -3160,9 +3160,13 @@ export function parseEmoji(text: string): Array<threema.EmojiInfo | string> {
 
 /**
  * Translate a shortname to UTF8.
+ *
+ * If the shortname is unknown, `null` will be returned.
+ *
+ * Case will be ignored (the input will be converted to lowercase).
  */
 export function shortnameToUtf8(shortname: string): string | null {
-    return SHORTNAMES[shortname] || null;
+    return SHORTNAMES[shortname.toLowerCase()] || null;
 }
 
 /**

+ 4 - 0
tests/ts/emoji_helpers.ts

@@ -133,6 +133,10 @@ describe('Emoji Helpers', () => {
         it('handles multi-codepoint emoji', function() {
             expect(shortnameToUtf8('flag_ch')).toEqual('\ud83c\udde8\ud83c\udded');
         });
+
+        it('ignores case', function() {
+            expect(shortnameToUtf8('Flag_CH')).toEqual('\ud83c\udde8\ud83c\udded');
+        });
     });
 
     describe('enlargeSingleEmoji', function() {