From b33cc3c75cda5d42c294deaaf582f691efb4288a Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Thu, 28 Aug 2025 09:49:14 -0400 Subject: [PATCH] Disallow non-BMP characters in occupant nicknames --- telegram/utils.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/telegram/utils.go b/telegram/utils.go index fa48164..7bdf588 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -70,6 +70,8 @@ var replyRegex = regexp.MustCompile("\\A>>? ?([0-9]+)\\n") const newlineChar string = "\n" const messageHeaderSeparator string = " | " // no hrunicode allowed here yet +var bmpCeil = rune(0x0000ffff) + // ChatType is an enum of chat types, roughly corresponding to TDLib's one but better type ChatType int @@ -859,6 +861,15 @@ func (c *Client) GetMUCNickname(chatID int64) string { } fc := c.FormatContact(chatID) rp, err := gateway.ResourcePrep(fc) + if err == nil { + // additionally check for non-BMP characters + for _, r := range rp { + if r > bmpCeil { + err = errors.New("Non-BMP character") + break + } + } + } if err != nil { log.Warnf("Resourceprep for %v failed, falling back to chat ID", fc)