Skip to content

Commit cf551cf

Browse files
committed
If the range location can't be found, return without attempting to add a link. This would crash previously.
1 parent ea62827 commit cf551cf

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

Sources/Attributer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ open class Attributer {
565565
*/
566566
open func makeInteract(_ callback: @escaping ((_ link: String) -> ())) -> Attributer {
567567
for nsRange in self.ranges {
568+
guard nsRange.location != NSNotFound else { return self }
568569
let unEscapedString = (self.attributedText.string as NSString).substring(with: nsRange)
569570
let escapedString = unEscapedString.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlHostAllowed) ?? ""
570571
self.attributedText.addAttribute(NSAttributedString.Key.link, value: "AttributedTextView:\(escapedString)", range: nsRange)

0 commit comments

Comments
 (0)