Skip to content

fix: drop leading zeros before building WhatsApp links - #225

Merged
Janani-bn merged 1 commit into
Janani-bn:mainfrom
Harinig-prog:fix/whatsapp-leading-zero
Oct 22, 2026
Merged

Janani-bn merged 1 commit into
Janani-bn:mainfrom
Harinig-prog:fix/whatsapp-leading-zero

Conversation

@Harinig-prog

Copy link
Copy Markdown
Contributor

Closes #224

What was wrong

Numbers with a leading trunk 0 or international 00 prefix pass validation (it only counts digits) and were turned into wa.me links that start with 0, which WhatsApp can't resolve.

Fix

In generateWhatsAppLink, strip leading zeros right after removing non-digits. No country code starts with 0, so this is always safe; the existing rules (add 91 to 10 digits, reject more than 15) then apply as before. A number that is only zeros now returns null, which the create-complaint response and success view already handle.

Tests

Three new cases in backend/tests/whatsapp.test.js: trunk 0, international 00 (India and US), and all zeros. All three fail on main and pass with this change. npm test in backend/: 81 tests, 81 pass.

Validation accepts any phone with at least ten digits, so numbers written
with India's trunk prefix (09876543210) or an international 00 prefix
(0091 98765 43210) reached generateWhatsAppLink. It only added 91 to
exactly-10-digit values and passed the rest through, producing links like
wa.me/09876543210 that WhatsApp can't resolve: wa.me expects the country
code with no leading zeros.

Strip leading zeros first (no country code starts with 0), then apply the
existing rules. A number that is all zeros now returns null.
@Janani-bn
Janani-bn merged commit 222b2b5 into Janani-bn:main Oct 22, 2026
1 check passed
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.

WhatsApp links break for numbers with a leading 0 or 00

2 participants