Repository navigation
Do not skip the character after a match in PhoneNumberMatcher - #773
Merged
Merged
Conversation
next() moved searchIndex to the end of the last match and then always incremented it, so the search for the next number started one character late. Java sets searchIndex = lastMatch.end() without the increment. When a number starts right after the previous one, its first character was lost: in "033316005+64 3 331 6005" the second match was "64 3 331 6005" instead of "+64 3 331 6005", and a number without its plus sign can be parsed with the wrong country calling code.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #773 +/- ##
============================================
- Coverage 86.12% 86.12% -0.01%
Complexity 1320 1320
============================================
Files 31 31
Lines 3445 3444 -1
============================================
- Hits 2967 2966 -1
Misses 478 478 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
When a number starts right after the previous match,
findNumbers()drops its first character:Without its
+(or its opening(, or a leading digit), the second number can be parsed with the wrong country calling code. For example,findNumbers('2024-01-02+4930123456', 'GB', Leniency::POSSIBLE())returns4930123456as +444930123456, where Java returns+4930123456.PhoneNumberMatcher::next()sets$this->searchIndex = $this->lastMatch->end()and then always increments it, so the next search starts one character after the end of the previous match. In Java'shasNext()there is no increment:This removes the increment. A match is never empty, so the search still moves forward.
testSequenceStartingRightAfterPreviousMatchfollowstestSequences, with no separator between the two numbers. It fails without the change (start 15, raw string64 3 331 6005) and passes with it.I compared this branch with Java libphonenumber 9.0.41 on 20,000 generated
findNumbers()texts with numbers back to back. Measured on top of the companion STRICT_GROUPING fix, 297 of the 316findNumbers()mismatches left after that fix are gone, and no new ones appear. The remaining ones involve trailing extension markers such asextandx.vendor/bin/phpunit,php-cs-fixer fix --dry-runandphpstanpass. The one exception isLocaleTestdata set #174 (SH, "St. Helena"), which also fails on master.