mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-22 02:32:02 -08:00
Escape html on username (telegram). Closes #378
This commit is contained in:
parent
0bc9c70c66
commit
dbf8a326d5
@ -1,6 +1,7 @@
|
|||||||
package btelegram
|
package btelegram
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"html"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -83,7 +84,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
|
|||||||
// Upload a file if it exists
|
// Upload a file if it exists
|
||||||
if msg.Extra != nil {
|
if msg.Extra != nil {
|
||||||
for _, rmsg := range helper.HandleExtra(&msg, b.General) {
|
for _, rmsg := range helper.HandleExtra(&msg, b.General) {
|
||||||
b.sendMessage(chatid, rmsg.Username+rmsg.Text)
|
b.sendMessage(chatid, rmsg.Username, rmsg.Text)
|
||||||
}
|
}
|
||||||
// check if we have files to upload (from slack, telegram or mattermost)
|
// check if we have files to upload (from slack, telegram or mattermost)
|
||||||
if len(msg.Extra["file"]) > 0 {
|
if len(msg.Extra["file"]) > 0 {
|
||||||
@ -114,7 +115,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Post normal message
|
// Post normal message
|
||||||
return b.sendMessage(chatid, msg.Username+msg.Text)
|
return b.sendMessage(chatid, msg.Username, msg.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
||||||
@ -372,16 +373,19 @@ func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64) (string,
|
|||||||
b.Log.Errorf("file upload failed: %#v", err)
|
b.Log.Errorf("file upload failed: %#v", err)
|
||||||
}
|
}
|
||||||
if fi.Comment != "" {
|
if fi.Comment != "" {
|
||||||
b.sendMessage(chatid, msg.Username+fi.Comment)
|
b.sendMessage(chatid, msg.Username, fi.Comment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Btelegram) sendMessage(chatid int64, text string) (string, error) {
|
func (b *Btelegram) sendMessage(chatid int64, username, text string) (string, error) {
|
||||||
m := tgbotapi.NewMessage(chatid, text)
|
m := tgbotapi.NewMessage(chatid, "")
|
||||||
|
m.Text = username + text
|
||||||
if b.Config.MessageFormat == "HTML" {
|
if b.Config.MessageFormat == "HTML" {
|
||||||
b.Log.Debug("Using mode HTML")
|
b.Log.Debug("Using mode HTML")
|
||||||
|
username = html.EscapeString(username)
|
||||||
|
m.Text = username + text
|
||||||
m.ParseMode = tgbotapi.ModeHTML
|
m.ParseMode = tgbotapi.ModeHTML
|
||||||
}
|
}
|
||||||
if b.Config.MessageFormat == "Markdown" {
|
if b.Config.MessageFormat == "Markdown" {
|
||||||
|
Loading…
Reference in New Issue
Block a user