From 4ac489e9a874473a89cca0319e1893c33c8c41d7 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Thu, 27 Mar 2025 11:22:43 +1100 Subject: [PATCH] Fixed an index out of bounds crash when ending a message with a mention --- Session/Utilities/MentionUtilities.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Session/Utilities/MentionUtilities.swift b/Session/Utilities/MentionUtilities.swift index 950076462..193d6a8c5 100644 --- a/Session/Utilities/MentionUtilities.swift +++ b/Session/Utilities/MentionUtilities.swift @@ -115,7 +115,12 @@ public enum MentionUtilities { result.addAttribute(.currentUserMentionBackgroundCornerRadius, value: (8 * sizeDiff), range: mention.range) result.addAttribute(.currentUserMentionBackgroundPadding, value: (3 * sizeDiff), range: mention.range) result.addAttribute(.currentUserMentionBackgroundColor, value: primaryColor.color, range: mention.range) - result.addAttribute(.kern, value: (3 * sizeDiff), range: NSRange(location: mention.range.upperBound, length: 1)) + + // Only add the additional kern if the mention isn't at the end of the string (otherwise this + // would crash due to an index out of bounds exception) + if mention.range.upperBound < result.length { + result.addAttribute(.kern, value: (3 * sizeDiff), range: NSRange(location: mention.range.upperBound, length: 1)) + } } switch (location, mention.isCurrentUser, theme.interfaceStyle) {