Prevent initializing styled body with out of range styles

This commit is contained in:
Harry 2023-08-01 09:37:02 -07:00 committed by GitHub
parent 129ba49903
commit c438d38ea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -57,7 +57,13 @@ public class StyleOnlyMessageBody: NSObject, Codable {
public init(text: String, collapsedStyles: [NSRangedValue<CollapsedStyle>]) {
self.text = text
self.collapsedStyles = collapsedStyles
let textRange = NSRange(location: 0, length: (text as NSString).length)
self.collapsedStyles = collapsedStyles.compactMap {
guard let intersection = $0.range.intersection(textRange), intersection.length > 0 else {
return nil
}
return .init($0.value, range: intersection)
}
}
public func asMessageBody() -> MessageBody {