Repository navigation
fix: drop leading zeros before building WhatsApp links - #225
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #224
What was wrong
Numbers with a leading trunk
0or international00prefix pass validation (it only counts digits) and were turned into wa.me links that start with0, 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 (add91to 10 digits, reject more than 15) then apply as before. A number that is only zeros now returnsnull, which the create-complaint response and success view already handle.Tests
Three new cases in
backend/tests/whatsapp.test.js: trunk0, international00(India and US), and all zeros. All three fail onmainand pass with this change.npm testinbackend/: 81 tests, 81 pass.