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

E164 parsing issue with +3758105261733 (national only number formatted as E.164). #3358

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3020,9 +3020,12 @@ boolean maybeStripNationalPrefixAndCarrierCode(
if (transformRule == null || transformRule.length() == 0
|| prefixMatcher.group(numOfGroups) == null) {
// If the original number was viable, and the resultant number is not, we return.
if (isViableOriginalNumber
if ((isViableOriginalNumber
&& !matcherApi.matchNationalNumber(
number.substring(prefixMatcher.end()), generalDesc, false)) {
number.substring(prefixMatcher.end()), generalDesc, false))||
(getNumberTypeHelper(number.toString(), metadata) != PhoneNumberType.UNKNOWN
&& getNumberTypeHelper(number.substring(prefixMatcher.end()), metadata)
== PhoneNumberType.UNKNOWN)) {
return false;
}
if (carrierCode != null && numOfGroups > 0 && prefixMatcher.group(numOfGroups) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,9 @@ public void testMaybeStripNationalPrefix() {
metadata
.getGeneralDescBuilder()
.setNationalNumberPattern("\\d{4,8}");
metadata
.getGeneralDescBuilder()
.addPossibleLength(6);
StringBuilder numberToStrip = new StringBuilder("34356778");
String strippedNumber = "356778";
assertTrue(phoneUtil.maybeStripNationalPrefixAndCarrierCode(numberToStrip, metadata.build(), null));
Expand All @@ -1866,6 +1869,21 @@ public void testMaybeStripNationalPrefix() {
assertEquals("Should have had no change - after stripping, it wouldn't have matched "
+ "the national rule.",
strippedNumber, numberToStrip.toString());
metadata.setNationalPrefixForParsing("0|80?");
metadata.setPremiumRate(
metadata
.getGeneralDescBuilder()
.setNationalNumberPattern("(?:810|902)\\d{7}"));
metadata.setPremiumRate(metadata.getGeneralDescBuilder().addPossibleLength(10));
numberToStrip = new StringBuilder("8105261733");
strippedNumber = "8105261733";
assertFalse(
phoneUtil.maybeStripNationalPrefixAndCarrierCode(numberToStrip, metadata.build(), null));
assertEquals(
"Should have had no change - after stripping, it wouldn't have matched "
+ "the national rule.",
strippedNumber,
numberToStrip.toString());
// Test extracting carrier selection code.
metadata.setNationalPrefixForParsing("0(81)?");
numberToStrip = new StringBuilder("08122123456");
Expand Down
Loading