Disallow non-BMP characters in occupant nicknames

This commit is contained in:
Bohdan Horbeshko 2025-08-28 09:49:14 -04:00
parent 7c9ea42f99
commit b33cc3c75c

View file

@ -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)