fix(utils): strip plus prefix from user JIDs in ParseJID

Adapted from upstream PR #224 (danie1net0). Queries addressed to
"+<number>@s.whatsapp.net" are never answered by WhatsApp and hang until
the IQ timeout (upstream issue #223: /user/info and /user/avatar hang 75s).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
jfengandClaude Opus 5.5 committed 2026-11-09 12:04:14 -03:00
1 parent fc35d72029
commit c33b4d98fd
2 files changed
+9 -2

No files matched your search

+7
View File
@@ -207,6 +207,13 @@ func ParseJID(arg string) (whatsmeow_types.JID, bool) {
return recipient, false return recipient, false
} }
// CreateJID keeps the "+" prefix for IsOnWhatsApp, but it is not part of a
// user JID. WhatsApp does not answer queries addressed to "+<number>", so
// they hang until the IQ timeout (upstream #223 / PR #224).
if recipient.Server == whatsmeow_types.DefaultUserServer {
recipient.User = strings.TrimPrefix(recipient.User, "+")
}
if recipient.User == "" &&!strings.Contains(jidString, "@broadcast") { if recipient.User == "" &&!strings.Contains(jidString, "@broadcast") {
logger.LogError("Invalid JID. No user specified: %s", jidString) logger.LogError("Invalid JID. No user specified: %s", jidString)
return recipient, false return recipient, false
+2 -2
View File
@@ -284,13 +284,13 @@ func TestParseJID(t *testing.T) {
name: "Valid phone number", name: "Valid phone number",
input: "15551234567", input: "15551234567",
expectOk: true, expectOk: true,
expectJID: "+[email protected]", expectJID: "[email protected]",
}, },
{ {
name: "Valid BR number", name: "Valid BR number",
input: "5531987654321", input: "5531987654321",
expectOk: true, expectOk: true,
expectJID: "+[email protected]", expectJID: "[email protected]",
}, },
{ {
name: "Valid group ID", name: "Valid group ID",