Fix crash on invalid URL

This commit is contained in:
Shadowfacts 2018-08-18 16:07:34 -04:00
parent 354b3469a8
commit a6f8565ab3
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 13 additions and 10 deletions

View File

@ -38,9 +38,9 @@ class StatusTableViewCell: UITableViewCell {
let doc = try! SwiftSoup.parse(status.content) let doc = try! SwiftSoup.parse(status.content)
let body = doc.body()! let body = doc.body()!
print("---") // print("---")
print(status.content) // print(status.content)
print("---") // print("---")
let text = attributedTextForNode(body) let text = attributedTextForNode(body)
contentLabel.attributedText = text contentLabel.attributedText = text
@ -74,13 +74,16 @@ class StatusTableViewCell: UITableViewCell {
case "br": case "br":
attributed.append(NSAttributedString(string: "\n")) attributed.append(NSAttributedString(string: "\n"))
case "a": case "a":
let linkRange = NSRange(location: 0, length: attributed.length) if let link = try? node.attr("href"),
let linkAttributes: [NSAttributedString.Key: Any] = [ let url = URL(string: link) {
.foregroundColor: UIColor.blue let linkRange = NSRange(location: 0, length: attributed.length)
] let linkAttributes: [NSAttributedString.Key: Any] = [
attributed.setAttributes(linkAttributes, range: linkRange) .foregroundColor: UIColor.blue
let link = try! node.attr("href") ]
links[linkRange] = URL(string: link)! attributed.setAttributes(linkAttributes, range: linkRange)
links[linkRange] = url
}
default: default:
break break
} }