mirror of
https://github.com/cwinfo/matterbridge.git
synced 2024-11-28 21:51:35 +00:00
Besides the bound checking, this now also use utf16 as suggested by https://github.com/go-telegram-bot-api/telegram-bot-api/issues/231
This commit is contained in:
parent
e60949ff3f
commit
1fb91c6316
@ -5,10 +5,11 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode/utf16"
|
||||||
|
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
"github.com/42wim/matterbridge/bridge/helper"
|
"github.com/42wim/matterbridge/bridge/helper"
|
||||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b *Btelegram) handleUpdate(rmsg *config.Message, message, posted, edited *tgbotapi.Message) *tgbotapi.Message {
|
func (b *Btelegram) handleUpdate(rmsg *config.Message, message, posted, edited *tgbotapi.Message) *tgbotapi.Message {
|
||||||
@ -375,8 +376,13 @@ func (b *Btelegram) handleEntities(rmsg *config.Message, message *tgbotapi.Messa
|
|||||||
b.Log.Errorf("entity text_link url parse failed: %s", err)
|
b.Log.Errorf("entity text_link url parse failed: %s", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
link := rmsg.Text[e.Offset : e.Offset+e.Length]
|
utfEncodedString := utf16.Encode([]rune(rmsg.Text))
|
||||||
rmsg.Text = strings.Replace(rmsg.Text, link, url.String(), 1)
|
if e.Offset+e.Length > len(utfEncodedString) {
|
||||||
|
b.Log.Errorf("entity length is too long %d > %d", e.Offset+e.Length, len(utfEncodedString))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
link := utf16.Decode(utfEncodedString[e.Offset : e.Offset+e.Length])
|
||||||
|
rmsg.Text = strings.Replace(rmsg.Text, string(link), url.String(), 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user