From 3847d38b6543099771907930e38e9e1cfa8bdcab Mon Sep 17 00:00:00 2001 From: Abitofevrything <54505189+abitofevrything@users.noreply.github.com> Date: Mon, 11 Sep 2023 02:39:35 -0700 Subject: [PATCH] Correctly decode emoji data as UTF-8 (#11) * Correctly decode emoji data as UTF-8 * Add tests --- lib/src/emoji.dart | 2 +- test/integration/emoji_test.dart | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/emoji.dart b/lib/src/emoji.dart index 4fe3d63..9f21361 100644 --- a/lib/src/emoji.dart +++ b/lib/src/emoji.dart @@ -81,7 +81,7 @@ Future> getEmojiDefinitions() async { return _cachedEmojiDefinitions!; } else { final response = await http.get(_emojiDefinitionsUrl); - final data = jsonDecode(response.body)['emojiDefinitions']; + final data = jsonDecode(utf8.decode(response.bodyBytes))['emojiDefinitions']; _cachedAt = DateTime.timestamp(); return _cachedEmojiDefinitions = [ diff --git a/test/integration/emoji_test.dart b/test/integration/emoji_test.dart index 18af2c9..9d8ff2d 100644 --- a/test/integration/emoji_test.dart +++ b/test/integration/emoji_test.dart @@ -7,4 +7,10 @@ void main() { expect(emojis, isNotEmpty); }); + + test('getEmojiDefinitions correcly decodes emojis', () async { + final emoji = (await getEmojiDefinitions()).singleWhere((element) => element.primaryName == 'heart'); + + expect(emoji.surrogates, equals('❤️')); + }); }