Skip to content

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

Open
danie1net0 wants to merge 1 commit into
evolution-foundation:developfrom
danie1net0:fix/jid-plus-prefix
Open

danie1net0 wants to merge 1 commit into
evolution-foundation:developfrom
danie1net0:fix/jid-plus-prefix

Conversation

@danie1net0

@danie1net0 danie1net0 commented Nov 2, 2026 •

Copy link
Copy Markdown

Fixes #223

Problem

utils.CreateJID returns +<number>@s.whatsapp.net. The + is needed for IsOnWhatsApp, but utils.ParseJID passes that string to types.ParseJID, so the + ends up in JID.User. WhatsApp never answers queries addressed to +<number>@s.whatsapp.net, so /user/info and /user/avatar with a phone number hang until the 75s IQ timeout and return 500.

Change

  • ParseJID strips the + from JID.User when the server is s.whatsapp.net. CreateJID is unchanged, so IsOnWhatsApp still gets the +.
  • TestParseJID expected the + in the output. Updated it and added cases for a number with +, a full JID with +, and a LID.

The strip before SendMessage in send_service.go is now redundant for JIDs built by ParseJID, but I left it in place to keep this change small.

Testing

Against a connected instance:

Request Before After
POST /user/info {"number":["55…"]} 500 after 75s 200 in ~0.16s
POST /user/info {"number":["+55…"]} 500 after 75s 200 in ~0.16s
POST /user/avatar {"number":"55…"} 500 after 75s 200 in ~0.16s
POST /user/check 200 200
POST /send/text 200 200

go build ./..., go vet and go test ./pkg/... pass.

Note: to connect on current develop I had to bump waVersion in the whatsmeow-lib submodule locally (the pinned version gets Client outdated (405)). That change is not part of this PR.

Summary by Sourcery

Normalize WhatsApp user JIDs to prevent failed queries caused by plus-prefixed phone numbers.

Bug Fixes:

  • Normalize WhatsApp user JIDs by removing a leading + so user information and avatar requests are addressed correctly instead of timing out.

Enhancements:

  • Expand JID parsing coverage for plus-prefixed phone numbers, full user JIDs, and LIDs.

CreateJID keeps the "+" prefix for IsOnWhatsApp, and ParseJID carried it
into JID.User. WhatsApp does not answer queries addressed to
"+<number>@s.whatsapp.net", so /user/info and /user/avatar hung until the
75s IQ timeout and returned 500.
@sourcery-ai

sourcery-ai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

ParseJID now removes a leading plus from WhatsApp user JIDs, preventing /user/info and /user/avatar queries from timing out while preserving CreateJID and IsOnWhatsApp behavior; tests cover normalized phone inputs, full JIDs, and LIDs.

Sequence diagram for normalized user JID queries

sequenceDiagram
    participant API as User API
    participant ParseJID
    participant WhatsApp as WhatsApp

    API->>ParseJID: ParseJID(number)
    ParseJID->>ParseJID: strings.TrimPrefix(user, "+")
    ParseJID-->>API: JID without leading +
    API->>WhatsApp: /user/info or /user/avatar query
    WhatsApp-->>API: Response
Loading

File-Level Changes

Change Details Files
Normalize phone-number JIDs returned by ParseJID so WhatsApp user queries omit the transport-only plus prefix.
  • Strip a leading "+" from the user component only for the default WhatsApp user server.
  • Preserve CreateJID behavior so IsOnWhatsApp continues receiving plus-prefixed numbers.
  • Retain the existing send-message normalization as a compatible redundant safeguard.
pkg/utils/utils.go
Expand ParseJID coverage to verify normalized phone JIDs and unchanged non-user JIDs.
  • Update phone-number expectations to omit the plus prefix.
  • Add inputs for plus-prefixed numbers and full JIDs.
  • Add a LID case confirming its user value is unchanged.
pkg/utils/utils_test.go

Possibly linked issues

  • #unknown: The PR removes the leading plus from s.whatsapp.net JIDs in ParseJID, directly fixing the reported endpoint timeouts.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

fmedeiros95 added a commit to fmedeiros95/evolution-go that referenced this pull request Nov 4, 2026
Adapt official PR evolution-foundation#224; preserve group and LID identifiers and document the distinction from phone existence checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant