damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit d5c45dc8ba206de0cd0477f26fec2ecc34d19f3d
parent 603a5a18144abc98786a383356c7c39930861fec
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 19 Feb 2023 09:20:09 -0800

Fix rare markdown crash

Diffstat:
Mdamus/Util/Markdown.swift | 7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/damus/Util/Markdown.swift b/damus/Util/Markdown.swift @@ -8,8 +8,8 @@ import Foundation public struct Markdown { - private let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) - + private var detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) + /// Ensure the specified URL has a scheme by prepending "https://" if it's absent. static func withScheme(_ url: any StringProtocol) -> any StringProtocol { return url.contains("://") ? url : "https://" + url @@ -31,6 +31,9 @@ public struct Markdown { /// Process the input text and add markdown for any embedded URLs. public func process(_ input: String) -> AttributedString { + guard let detector else { + return AttributedString(stringLiteral: input) + } let matches = detector.matches(in: input, options: [], range: NSRange(location: 0, length: input.utf16.count)) var output = input // Start with the last match, because replacing the first would invalidate all subsequent indices