Fix crash on attachment-only statuses posted from pleromafe
This commit is contained in:
parent
db68b9dee0
commit
07a79657a7
|
@ -10,13 +10,13 @@ import Foundation
|
|||
|
||||
extension NSMutableAttributedString {
|
||||
|
||||
func trimCharactersInSet(_ charSet: CharacterSet) {
|
||||
func trimTrailingCharactersInSet(_ charSet: CharacterSet) {
|
||||
var range = (string as NSString).rangeOfCharacter(from: charSet)
|
||||
|
||||
while range.length != 0 && range.location == 0 {
|
||||
replaceCharacters(in: range, with: "")
|
||||
range = (string as NSString).rangeOfCharacter(from: charSet)
|
||||
}
|
||||
// while range.length != 0 && range.location == 0 {
|
||||
// replaceCharacters(in: range, with: "")
|
||||
// range = (string as NSString).rangeOfCharacter(from: charSet)
|
||||
// }
|
||||
|
||||
range = (string as NSString).rangeOfCharacter(from: charSet, options: .backwards)
|
||||
while range.length != 0 && range.length + range.location == length {
|
||||
|
|
|
@ -28,7 +28,12 @@ class ContentLabel: TTTAttributedLabel {
|
|||
|
||||
let (attributedText, links) = attributedTextForHTMLNode(body)
|
||||
let mutAttrString = NSMutableAttributedString(attributedString: attributedText)
|
||||
mutAttrString.trimCharactersInSet(.whitespacesAndNewlines)
|
||||
|
||||
// only trailing whitespace can be trimmed here
|
||||
// when posting an attachment without any text, pleromafe includes U+200B ZERO WIDTH SPACE at the beginning
|
||||
// this would get trimmed and cause range out of bounds crashes
|
||||
mutAttrString.trimTrailingCharactersInSet(.whitespacesAndNewlines)
|
||||
|
||||
mutAttrString.addAttribute(.font, value: font, range: NSRange(location: 0, length: mutAttrString.length))
|
||||
self.text = mutAttrString
|
||||
for (range, url) in links {
|
||||
|
|
Loading…
Reference in New Issue