Escape special characters inside alert name (#13)

This commit is contained in:
Egor Cherniak 2023-07-04 11:39:07 +03:00 committed by GitHub
parent e068525360
commit 430d5c3b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -60,7 +60,8 @@ public class MenuCallbackMapper {
if (!userAlerts.isEmpty()) {
StringBuilder text = new StringBuilder("Ваши алерты:\n");
userAlerts.forEach(userAlert -> text.append("*id:* ").append(userAlert.getId())
.append("\n*Название:* ").append(userAlert.getName())
.append("\n*Название:* ")
.append(escapeSpecialCharacters(userAlert.getName()))
.append("\n"));
message.setText(text.toString());
message.setParseMode("MarkdownV2");
@ -93,4 +94,13 @@ public class MenuCallbackMapper {
message.setReplyMarkup(buildMainInlineKeyboardMarkup());
return message;
}
private String escapeSpecialCharacters(String message) {
return message
.replace("_", "\\_")
.replace("*", "\\*")
.replace("[", "\\[")
.replace("`", "\\`")
.replace(".", "\\.");
}
}