diff --git a/app/src/main/java/com/idormy/sms/forwarder/utils/sender/TelegramUtils.kt b/app/src/main/java/com/idormy/sms/forwarder/utils/sender/TelegramUtils.kt index 4cdede0c..effb9c0c 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/utils/sender/TelegramUtils.kt +++ b/app/src/main/java/com/idormy/sms/forwarder/utils/sender/TelegramUtils.kt @@ -52,7 +52,7 @@ class TelegramUtils private constructor() { } else { val bodyMap: MutableMap = mutableMapOf() bodyMap["chat_id"] = setting.chatId - bodyMap["text"] = content + bodyMap["text"] = htmlEncode(content) bodyMap["parse_mode"] = "HTML" bodyMap["disable_web_page_preview"] = "true" val requestMsg: String = Gson().toJson(bodyMap) @@ -132,5 +132,23 @@ class TelegramUtils private constructor() { fun sendMsg(setting: TelegramSetting, msgInfo: MsgInfo) { sendMsg(setting, msgInfo, null, null) } + + private fun htmlEncode(source: String?): String { + if (source == null) { + return "" + } + val buffer = StringBuffer() + for (element in source) { + when (element) { + '<' -> buffer.append("<") + '>' -> buffer.append(">") + '&' -> buffer.append("&") + '"' -> buffer.append(""") + //10, 13 -> buffer.append("\n") + else -> buffer.append(element) + } + } + return buffer.toString() + } } } \ No newline at end of file