From 19fd207470854299ae6b90287d6a451f117e56dc Mon Sep 17 00:00:00 2001 From: Kyle Matthew Hedden Date: Wed, 13 Jul 2022 11:32:12 -0400 Subject: [PATCH] insert label range validations to prevent crashes --- MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index c524b7b3..edb8c1a2 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -829,7 +829,14 @@ extension Label { private func addActionAttributes(range: NSRange, string: NSMutableAttributedString?) { - guard let string = string else { return } + guard let string = string, + range.location > 0 && range.location < string.length + else { return } + + var range = range + if range.upperBound > string.length { + range = NSRange(location: range.location, length: string.length - range.location) + } string.addAttributes([NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue], range: range) }