From 244f2ed9119eb0c541852aae819e006be4d8fb1a Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Tue, 1 Nov 2022 14:45:00 +0000 Subject: [PATCH] Fix crash on duplicate custom emojis Fixes #274 Add a merge function to `Collectors.toMap` to discard any duplicate custom emojis that may be returned if a user uses the same custom emoji in both their name and profile. --- .../org/joinmastodon/android/ui/text/HtmlParser.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java index ec3757dd..a27ced1d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java @@ -129,7 +129,16 @@ public class HtmlParser{ } public static void parseCustomEmoji(SpannableStringBuilder ssb, List emojis){ - Map emojiByCode=emojis.stream().collect(Collectors.toMap(e->e.shortcode, Function.identity())); + Map emojiByCode = + emojis.stream() + .collect( + Collectors.toMap(e->e.shortcode, Function.identity(), (emoji1, emoji2) -> { + // Ignore duplicate shortcodes and just take the first, it will be + // the same emoji anyway + return emoji1; + }) + ); + Matcher matcher=EMOJI_CODE_PATTERN.matcher(ssb); int spanCount=0; CustomEmojiSpan lastSpan=null;