Fix number with leading 0 after country code#89
Closed
thvdveld wants to merge 2 commits intowhisperfish:mainfrom
Closed
Fix number with leading 0 after country code#89thvdveld wants to merge 2 commits intowhisperfish:mainfrom
thvdveld wants to merge 2 commits intowhisperfish:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #89 +/- ##
==========================================
+ Coverage 67.81% 68.63% +0.81%
==========================================
Files 18 18
Lines 2172 2216 +44
==========================================
+ Hits 1473 1521 +48
+ Misses 699 695 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c24f046 to
65499ea
Compare
rubdos
reviewed
Oct 9, 2025
Member
rubdos
left a comment
There was a problem hiding this comment.
What about: you make the country binding mutable, and you try to eagerly assign it (with the block you just wrote), and you do the same with the national binding, resetting the country if your guess was wrong?
| // Normalize the number and extract country code. | ||
| number = helper::country_code(database, country, number)?; | ||
|
|
||
| let country = if country.is_none() { |
Member
There was a problem hiding this comment.
Suggested change
| let country = if country.is_none() { | |
| let country = country.or_else(|| { |
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.
Fixes the parsing of phone numbers with a leading 0 after the country code, such as "+330631966543".
The parsing does not fail when doing:
parse(Some(country::FR), "+330631966543")However, it does fail when the country code is not passed to it:
parse(None, "+330631966543")When the country code is not passed to it, then the following block is not executed (which removes the national prefix when present):
When parsing the number, we should find out what the country code is and then strip the national prefix, which is what this PR does. However, I'm not satisfied with how it turns out since detecting the country code is now duplicated. Normally, getting the country code is done with the
Countryhelper struct that takes a&PhoneNumber.This PR also adds a test case for the formatting of numbers with a national prefix.
Fixes #81