From 67ad8b18e0496c0bf247e65c8e631013bab3c053 Mon Sep 17 00:00:00 2001 From: Luca Bernstein Date: Fri, 10 Dec 2021 09:45:19 +0100 Subject: [PATCH] Escape markdown chars in version --- bot/config.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bot/config.go b/bot/config.go index 344ca9d..2186d7c 100644 --- a/bot/config.go +++ b/bot/config.go @@ -197,13 +197,20 @@ func (bc *BotController) configHandleAbout(m *tb.Message, params ...string) { if version == "" { version = "not specified" } - _, err := bc.Bot.Send(m.Sender, fmt.Sprintf(`Version information about [LucaBernstein/beancount\-bot\-tg](https://github.com/LucaBernstein/beancount\-bot\-tg) + _, err := bc.Bot.Send(m.Sender, escapeCharacters(fmt.Sprintf(`Version information about [LucaBernstein/beancount-bot-tg](https://github.com/LucaBernstein/beancount-bot-tg) Version: [%s](%s)`, version, - strings.ReplaceAll(versionLink, "-", "\\-"), - ), tb.ModeMarkdownV2) + versionLink, + ), ".", "-"), tb.ModeMarkdownV2) if err != nil { bc.Logf(ERROR, m, "Sending bot message failed: %s", err.Error()) } } + +func escapeCharacters(s string, c ...string) string { + for _, char := range c { + s = strings.ReplaceAll(s, char, "\\"+char) + } + return s +}