Skip to content

Commit

Permalink
Skip parsing blogging reminders schedule when backgrounded
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdchr committed Mar 8, 2023
1 parent 6b26b0b commit 273fe08
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ private extension BloggingRemindersScheduleFormatter {
}

static func stringToAttributedString(_ string: String) -> NSAttributedString {
// When the app is in a background state, return the non-emphasized plain String instead.
// Parsing a HTML string in the background may lead to a crash.
// Refer to ReaderCommentsViewController.m:1088 for a similar scenario and explanation.
if UIApplication.shared.applicationState == .background {
return .init(string: string.removedHTMLEmphases())
}

let htmlData = NSString(string: string).data(using: String.Encoding.unicode.rawValue) ?? Data()
let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [.documentType: NSAttributedString.DocumentType.html]

Expand Down Expand Up @@ -176,3 +183,13 @@ private extension BloggingRemindersScheduleFormatter {
comment: "Short title telling the user they will receive a blogging reminder every day of the week.")
}
}

private extension String {
/// Convenient method to remove HTML emphasis tags from a given string.
func removedHTMLEmphases() -> String {
guard let expression = try? NSRegularExpression(pattern: "</?strong>", options: .caseInsensitive) else {
return self
}
return expression.stringByReplacingMatches(in: self, range: NSMakeRange(0, self.count), withTemplate: String())
}
}

0 comments on commit 273fe08

Please sign in to comment.