Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex-formatted text with URLs from Telegram gets randomly corrupted #909

Closed
ValdikSS opened this issue Sep 26, 2019 · 2 comments
Closed

Comments

@ValdikSS
Copy link
Contributor

Describe the bug
Long messages (posts forwarded to bridged chat from telegram channel) with multiple URLs gets corrupted: the URLs are misplaced and appear in the middle of the text, rewriting original text in this place.

See the screenshot.

с суммарным полезным объёмом ~45TB и начинаете ЭКСПЛУАТАЦИЮ.
became
с суммарным полезным объёhttps://t.me/TrTrTr8holes/119ПЛУАТАЦИЮ.

This URL should be in обои от стен отклеиваются

P.S. music.yandex.ru link on top is missing space before the link. I'm not sure if it's relevant to this bug.

To Reproduce
Open https://t.me/TrTrTr8holes/236 and forward it into bridged chat.

Expected behavior
The URLs are placed correctly

Screenshots/debug logs
Screenshot_20190926_212647-fs8

Environment (please complete the following information):

  • OS: Linux, x86_64
  • Matterbridge version: 1.15.1 87788f3

Additional context

[telegram.bridged]
…
RemoteNickFormat="{LABEL}<b>&lt;{NICK}&gt;</b> "
UseInsecureURL=false
MessageFormat="HTMLnick"
Label="[T] "
@42wim
Copy link
Owner

42wim commented Oct 26, 2019

Issue is probably in

func (b *Btelegram) handleEntities(rmsg *config.Message, message *tgbotapi.Message) {
if message.Entities == nil {
return
}
// for now only do URL replacements
for _, e := range *message.Entities {
if e.Type == "text_link" {
url, err := e.ParseURL()
if err != nil {
b.Log.Errorf("entity text_link url parse failed: %s", err)
continue
}
utfEncodedString := utf16.Encode([]rune(rmsg.Text))
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)
}
}
}
if anyone wants to debug.

go-telegram-bot-api/telegram-bot-api#231 is also related

@ValdikSS
Copy link
Contributor Author

Fixed by #1765

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants