Skip to content

Commit

Permalink
Escape markdown chars in version
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaBernstein committed Dec 10, 2021
1 parent 369c64e commit 67ad8b1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 67ad8b1

Please sign in to comment.