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

fix: Skip phone number validation when country code is unknown #1062

Merged
merged 4 commits into from
Nov 10, 2021

Conversation

barbeau
Copy link
Member

@barbeau barbeau commented Nov 10, 2021

Summary:

This PR ensures that phone number validation is skipped when country code is unknown (invalid or unprovided). Adds a unit test for this case as well.

Closes #1058.

Background:

The intent of making the country code optional in PR #851 was to skip phone number validation if country code wasn't provided at the command line. Apparently in the main branch phone number validation is run even when the country code is not provided or unknown.

I'm not sure if there was a regression (perhaps in PR #862?) or if we just didn't have sufficient unit test coverage initially to check all cases.

In the main branch we currently have a test:

    assertValid(
        nc ->
            new DefaultFieldValidator(CountryCode.forStringOrUnknown("ZZ"))
                .validatePhoneNumber("+1 (650) 253-0000", CELL_CONTEXT, nc));

...but this test doesn't cover this case and it still passes on the main branch. Evidently the phone number validation library considers +1 (650) 253-0000 a valid phone number even when no valid country code is provided (I'm assuming because it's an international format).

However, the phone number validation library does consider other formats (e.g., common US format 813-254-4278) invalid without a country code.

I've added another assertion to check an unknown country code with the US format, and this assertation fails on the current master branch but passes on this PR.

    assertValid(
            nc ->
                    new DefaultFieldValidator(CountryCode.forStringOrUnknown("ZZ"))
                            .validatePhoneNumber("813-254-4278", CELL_CONTEXT, nc));

Expected behavior:

When country code is not provided at the command-line, phone number validation should be skipped.


Please make sure these boxes are checked before submitting your pull request - thanks!

  • Run the unit tests with gradle test to make sure you didn't break anything
  • Format the title like "feat: [new feature short description]". Title must follow the Conventional Commit Specification(https://www.conventionalcommits.org/en/v1.0.0/).
  • Linked all relevant issues

@github-actions
Copy link
Contributor

This contribution does not follow the conventions set by the Google Java style guide. Please run the following command line at the root of the project to fix formatting errors: ./gradlew goJF.

Copy link
Collaborator

@aababilov aababilov left a comment

Choose a reason for hiding this comment

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

Thank you!

Comment on lines 128 to 130
// The below format fails validation without a known country code, so check that we skip
// validation when country
// code is unknown
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please merge the last two lines and put a full stop at the end.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for catching that! Not sure why the code formatter split the lines, but it's fixed now with the period too in 5223228.

@@ -93,6 +93,11 @@ public void validateEmail(
@Override
public void validatePhoneNumber(
String phoneNumber, GtfsCellContext cellContext, NoticeContainer noticeContainer) {
if (countryCode.isUnknown()) {
// If the user didn't provide a country code or the provided country-code was invalid, skip
// validation
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please put a full stop at the end of comments. They must be complete sentences.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 5223228.

@isabelle-dr
Copy link
Contributor

Thank you @barbeau!

We can then cancel PR #1061 when this is merged, problem solved 🎉

@lionel-nj
Copy link
Contributor

Thanks for working on that @barbeau, it seems that some unit test failed though: https://github.com/MobilityData/gtfs-validator/runs/4170664366?check_suite_focus=true.

We shouldn't be declaring any phone numbers invalid when an unknown country code is provided.
@barbeau
Copy link
Member Author

barbeau commented Nov 10, 2021

@lionel-nj Whoops, I accidentally restored that test in my original commit when testing locally - it should be removed because we don't want to run validation on unknown country codes. I removed it in 381683c so it should pass now.

Copy link
Contributor

@lionel-nj lionel-nj left a comment

Choose a reason for hiding this comment

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

After analyzing the validation reports produced by https://github.com/MobilityData/gtfs-validator/actions/runs/1446146385 - I confirm that no more InvalidPhoneNumberNotice is triggered. Thanks for fixing #1058 @barbeau!

@lionel-nj lionel-nj merged commit 649c164 into master Nov 10, 2021
@lionel-nj lionel-nj deleted the sean/fix-validate-phone-no-country-code branch November 10, 2021 23:21
@markstos markstos mentioned this pull request Nov 17, 2021
4 tasks
@isabelle-dr isabelle-dr added this to the v3.0.0 milestone Nov 18, 2021
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.

False positives for InvalidPhoneNumberNotice
4 participants