@@ -512,6 +512,14 @@ func StringToInt(s string) int {
512512 return i
513513}
514514
515+ func SanitizeName (text string ) string {
516+ newText := strings .ReplaceAll (text , "\n " , " " )
517+ if newText != text {
518+ LOG_DEBUG (fmt .Sprintf ("sanitized '%s' -> '%s'" , text , newText ))
519+ }
520+ return newText
521+ }
522+
515523// This function is called with single argument to obtain userId string
516524// or with two arguments (chatId, userId) to obtain a chatId string.
517525func JidToStr (client * whatsmeow.Client , defaultJid types.JID , altJids ... types.JID ) string {
@@ -1055,23 +1063,23 @@ func (handler *WmEventHandler) HandleLoggedOut() {
10551063
10561064func GetNameFromContactInfo (contactInfo types.ContactInfo ) string {
10571065 if len (contactInfo .FullName ) > 0 {
1058- return contactInfo .FullName
1066+ return SanitizeName ( contactInfo .FullName )
10591067 }
10601068
10611069 if len (contactInfo .FirstName ) > 0 {
1062- return contactInfo .FirstName
1070+ return SanitizeName ( contactInfo .FirstName )
10631071 }
10641072
10651073 if len (contactInfo .PushName ) > 0 {
1066- return contactInfo .PushName
1074+ return SanitizeName ( contactInfo .PushName )
10671075 }
10681076
10691077 if len (contactInfo .BusinessName ) > 0 {
1070- return contactInfo .BusinessName
1078+ return SanitizeName ( contactInfo .BusinessName )
10711079 }
10721080
10731081 if len (contactInfo .RedactedPhone ) > 0 {
1074- return contactInfo .RedactedPhone
1082+ return SanitizeName ( contactInfo .RedactedPhone )
10751083 }
10761084
10771085 return ""
0 commit comments