fix: notification not handle escaped HTML tag issue. ticket: #22627CDA

This commit is contained in:
CMK 2021-07-07 19:16:30 +08:00
parent 31f178eb3a
commit 1af870a157
1 changed files with 12 additions and 1 deletions

View File

@ -56,7 +56,7 @@ class NotificationService: UNNotificationServiceExtension {
bestAttemptContent.title = notification.title
bestAttemptContent.subtitle = ""
bestAttemptContent.body = notification.body
bestAttemptContent.body = notification.body.escape()
bestAttemptContent.sound = UNNotificationSound.init(named: UNNotificationSoundName(rawValue: "BoopSound.caf"))
bestAttemptContent.userInfo["plaintext"] = plaintextData
@ -105,3 +105,14 @@ extension NotificationService {
return try? P256.KeyAgreement.PublicKey(x963Representation: publicKeyData)
}
}
extension String {
func escape() -> String {
return self
.replacingOccurrences(of: "&", with: "&")
.replacingOccurrences(of: "&lt;", with: "<")
.replacingOccurrences(of: "&gt;", with: ">")
.replacingOccurrences(of: "&quot;", with: "\"")
.replacingOccurrences(of: "&apos;", with: "'")
}
}