From f46418534fbe65a71c90a93de08c7caf5ec072ba Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 29 Oct 2019 00:10:14 +0400 Subject: [PATCH] Don't crash on invalid highlight range --- submodules/ChatListUI/Sources/Node/ChatListItem.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/submodules/ChatListUI/Sources/Node/ChatListItem.swift b/submodules/ChatListUI/Sources/Node/ChatListItem.swift index 7199f20867..5be302526b 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListItem.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListItem.swift @@ -860,7 +860,10 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { if let chatListSearchResult = chatListSearchResult { for range in chatListSearchResult.resultRanges { - composedString.addAttribute(.foregroundColor, value: theme.messageHighlightedTextColor, range: NSRange(range, in: chatListSearchResult.text)) + let stringRange = NSRange(range, in: chatListSearchResult.text) + if stringRange.location >= 0 && stringRange.location + stringRange.length <= composedString.length { + composedString.addAttribute(.foregroundColor, value: theme.messageHighlightedTextColor, range: stringRange) + } } }