Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make phone parsing stricter #122

Merged
merged 2 commits into from
May 8, 2024
Merged

Make phone parsing stricter #122

merged 2 commits into from
May 8, 2024

Conversation

rowanseymour
Copy link
Member

We currently allow phone URNs to be any garbage that is up to 64 chars of alphanumeric characters... and then in courier we have to make it stricter in StrictTelForCountry https://github.com/nyaruka/courier/blob/29ce7cd76c13081efb5e61be45f32770c7a2722a/handlers/utils.go#L99

I don't see why we can't be stricter here..

}

// ParseNumber tries to extact a possible number or shortcode from the given string, returning an error if it can't.
func ParseNumber(raw string, country i18n.Country) (string, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

making this exported because it might be useful elsewhere like goflow

@rowanseymour rowanseymour requested a review from norkans7 May 8, 2024 15:39
for i, tc := range testCases {
urn, err := ParsePhone(tc.input, tc.country)
{"1", "RW", "", "the phone number supplied is not a number"},
{"1234", "RW", "", "not a possible number or shortcode"}, // RW short codes are 3 digits
Copy link
Member Author

Choose a reason for hiding this comment

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

@norkans7 true ?

Copy link
Contributor

Choose a reason for hiding this comment

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

wrong, there are short code with 4 digits

Copy link
Member Author

Choose a reason for hiding this comment

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

are those dialable numbers ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

Copy link
Member Author

Choose a reason for hiding this comment

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

I notice here in Ecuador I get messages from numbers like 8080 which libphonenumber doesn't recognize but I thought maybe they're only one way

Copy link
Member Author

Choose a reason for hiding this comment

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

@norkans7 updated to accept short codes that libphonenumber recognizes OR anything that matches ^[1-9][0-9]{2,4}$, e.g. 3-5 digits, not starting with a zero

Copy link
Contributor

Choose a reason for hiding this comment

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

why not 3-6 digits?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm assuming that libphonenumber mostly recognizes valid short codes so this is just a fallback.. and I'm trying to be careful to not start accepting local numbers as valid.. but we can make it 6 I guess.... updating...

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like to move all phone number validation into go eventually so that logic is consistent and in one place.

Copy link

codecov bot commented May 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.57%. Comparing base (40a12c7) to head (c9bf887).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #122      +/-   ##
==========================================
+ Coverage   89.54%   89.57%   +0.03%     
==========================================
  Files          43       43              
  Lines        1979     1986       +7     
==========================================
+ Hits         1772     1779       +7     
+ Misses        168      167       -1     
- Partials       39       40       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rowanseymour rowanseymour merged commit d055948 into main May 8, 2024
7 checks passed
@rowanseymour rowanseymour deleted the stricter_phone branch May 8, 2024 16:48
@github-actions github-actions bot locked and limited conversation to collaborators May 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants