Skip to content

1.2.1 - Change Detection

Compare
Choose a tag to compare
@rakuyoMo rakuyoMo released this 23 Oct 06:46
· 300 commits to master since this release

Fix

  • Fixed an issue where JSON could not be previewed due to the use of regular detection URLs.

In version 1.2.0, we use **regular ** to detect whether a string is a URL.

((https|http|ftp|rtsp|igmp|file|rtspt|rtspu)://)?((\\w)*|([0-9]*)|([-|_])*)+([\\.|/]((\\w)*|([0-9]*)|([-|_])*))+

It has been tested when the JSON content is very complex, such as {"address" : "0x97463213"}.

At this time, if you judge by this method, there will be no result for the method call and the method will just end. As a result, JSON cannot be displayed.

So in version 1.2.1, we have changed the way URLs are determined. The NSDataDetector type is used instead:

var isValidURL: String? {

    guard count > 1 else { return nil }
    
    guard let detector = try? NSDataDetector(
        types: NSTextCheckingResult.CheckingType.link.rawValue
    ) else { return nil }

    let string = removeEscaping()

    let matches = detector.matches(in: string, options: [], range: NSRange(location: 0, length: string.utf16.count))
    
    return matches.isEmpty ? nil : string
}