From 1af870a157d9bf5d322bbb79bff0433f0d4432ad Mon Sep 17 00:00:00 2001 From: CMK Date: Wed, 7 Jul 2021 19:16:30 +0800 Subject: [PATCH] fix: notification not handle escaped HTML tag issue. ticket: #22627CDA --- NotificationService/NotificationService.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/NotificationService/NotificationService.swift b/NotificationService/NotificationService.swift index 4e09e4939..cc81f0edd 100644 --- a/NotificationService/NotificationService.swift +++ b/NotificationService/NotificationService.swift @@ -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: "<", with: "<") + .replacingOccurrences(of: ">", with: ">") + .replacingOccurrences(of: """, with: "\"") + .replacingOccurrences(of: "'", with: "'") + } +}