Skip to content

Commit 6167ef8

Browse files
committed
fixes #429 - sanitize whatsapp contact names removing line breaks
1 parent 11a7696 commit 6167ef8

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

lib/common/src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77

88
#pragma once
99

10-
#define NCHAT_VERSION "5.11.32"
10+
#define NCHAT_VERSION "5.12.1"

lib/wmchat/go/gowm.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
517525
func JidToStr(client *whatsmeow.Client, defaultJid types.JID, altJids ...types.JID) string {
@@ -1055,23 +1063,23 @@ func (handler *WmEventHandler) HandleLoggedOut() {
10551063

10561064
func 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 ""

src/nchat.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
2-
.TH NCHAT "1" "November 2025" "nchat 5.11.32" "User Commands"
2+
.TH NCHAT "1" "November 2025" "nchat 5.12.1" "User Commands"
33
.SH NAME
44
nchat \- ncurses chat
55
.SH SYNOPSIS

0 commit comments

Comments
 (0)