Skip to content

Commit 0bd1332

Browse files
authored
Documented the issue with checking isPossible only for default country (#3771)
* Added Automatic-Module-Name to published jars. Context: https://b.corp.google.com/issues/308334884 * Removed Automatic-Module-Name from carrier and geocoder. Classes in these modules belong to the same package as core libphonenumber library, which leads to the split package problem with Java modules. * Documented the issue with checking isPossible only for default country
1 parent bf08a3c commit 0bd1332

File tree

5 files changed

+95
-60
lines changed

5 files changed

+95
-60
lines changed

cpp/src/phonenumbers/phonenumberutil.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,13 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
531531
// would most likely be area codes) and length (obviously includes the
532532
// length of area codes for fixed line numbers), it will return false for
533533
// the subscriber-number-only version.
534+
//
535+
// There is a known issue with this method: if a number is possible only in a
536+
// certain region among several regions that share the same country calling
537+
// code, this method will consider only the "main" region. For example,
538+
// +1310xxxx are valid numbers in Canada. However, they are not possible in
539+
// the US. As a result, this method will return false for +1310xxxx. See
540+
// https://issuetracker.google.com/issues/335892662 for more details.
534541
ValidationResult IsPossibleNumberWithReason(const PhoneNumber& number) const;
535542

536543
// Convenience wrapper around IsPossibleNumberWithReason(). Instead of
@@ -565,6 +572,13 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
565572
// would most likely be area codes) and length (obviously includes the
566573
// length of area codes for fixed line numbers), it will return false for
567574
// the subscriber-number-only version.
575+
//
576+
// There is a known issue with this method: if a number is possible only in a
577+
// certain region among several regions that share the same country calling
578+
// code, this method will consider only the "main" region. For example,
579+
// +1310xxxx are valid numbers in Canada. However, they are not possible in
580+
// the US. As a result, this method will return false for +1310xxxx. See
581+
// https://issuetracker.google.com/issues/335892662 for more details.
568582
ValidationResult IsPossibleNumberForTypeWithReason(
569583
const PhoneNumber& number, PhoneNumberType type) const;
570584

java/demo/src/main/resources/com/google/phonenumbers/demo/result.soy

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,44 +101,42 @@
101101
<TH>Result from isPossibleNumber()</TH>
102102
<TD>{$isPossibleNumber}</TD>
103103
</TR>
104-
{if $isPossibleNumber}
105-
{if $validationResult == "IS_POSSIBLE_LOCAL_ONLY"}
106104
<TR>
107105
<TH>Result from isPossibleNumberWithReason()</TH>
108106
<TD>{$validationResult}</TD>
109107
</TR>
110-
<TR>
111-
<TD colspan=2>Number is considered invalid as it is not a possible national number.</TD>
112-
</TR>
113-
{else}
114108
<TR>
115109
<TH>Result from isValidNumber()</TH>
116110
<TD>{$isValidNumber}</TD>
117111
</TR>
112+
{if $isValidNumber}
113+
{if $validationResult != "IS_POSSIBLE"}
114+
<TR>
115+
<TD colspan=2 style="color:red">
116+
Warning: This number represents a known <a href="https://issuetracker.google.com/issues/335892662">
117+
edge case</a> - it is a valid number, but it is not considered (strictly) possible
118+
</TD>
119+
</TR>
120+
{/if}
118121
{if $isValidNumberForRegion != null}
119-
<TR>
120-
<TH>Result from isValidNumberForRegion()</TH>
121-
<TD>{$isValidNumberForRegion}</TD>
122-
</TR>
122+
<TR>
123+
<TH>Result from isValidNumberForRegion()</TH>
124+
<TD>{$isValidNumberForRegion}</TD>
125+
</TR>
123126
{/if}
124127
<TR>
125128
<TH>Phone Number region</TH>
126-
<TD>{$phoneNumberRegion ?: ""}</TD>
129+
<TD>{$phoneNumberRegion}</TD>
127130
</TR>
128131
<TR>
129132
<TH>Result from getNumberType()</TH>
130133
<TD>{$numberType}</TD>
131134
</TR>
132-
{/if}
133-
{else}
134-
<TR>
135-
<TH>Result from isPossibleNumberWithReason()</TH>
136-
<TD>{$validationResult}</TD>
137-
</TR>
138-
<TR>
139-
<TD colspan=2>Note: Numbers that are not possible have type UNKNOWN, an unknown region, and are considered invalid.</TD>
140-
</TR>
141-
{/if}
135+
{else}
136+
<TR>
137+
<TD colspan=2>Note: Invalid numbers have type UNKNOWN and no region.</TD>
138+
</TR>
139+
{/if}
142140
</TABLE>
143141
</DIV>
144142

java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,6 +2708,13 @@ private ValidationResult testNumberLength(
27082708
* length (obviously includes the length of area codes for fixed line numbers), it will
27092709
* return false for the subscriber-number-only version.
27102710
* </ol>
2711+
*
2712+
* <p>There is a known <a href="https://issuetracker.google.com/issues/335892662">issue</a> with this
2713+
* method: if a number is possible only in a certain region among several regions that share the
2714+
* same country calling code, this method will consider only the "main" region. For example,
2715+
* +1310xxxx are valid numbers in Canada. However, they are not possible in the US. As a result,
2716+
* this method will return IS_POSSIBLE_LOCAL_ONLY for +1310xxxx.
2717+
*
27112718
* @param number the number that needs to be checked
27122719
* @return a ValidationResult object which indicates whether the number is possible
27132720
*/
@@ -2737,6 +2744,12 @@ public ValidationResult isPossibleNumberWithReason(PhoneNumber number) {
27372744
* return false for the subscriber-number-only version.
27382745
* </ol>
27392746
*
2747+
* <p>There is a known <a href="https://issuetracker.google.com/issues/335892662">issue</a> with this
2748+
* method: if a number is possible only in a certain region among several regions that share the
2749+
* same country calling code, this method will consider only the "main" region. For example,
2750+
* +1310xxxx are valid numbers in Canada. However, they are not possible in the US. As a result,
2751+
* this method will return IS_POSSIBLE_LOCAL_ONLY for +1310xxxx.
2752+
*
27402753
* @param number the number that needs to be checked
27412754
* @param type the type we are interested in
27422755
* @return a ValidationResult object which indicates whether the number is possible

javascript/i18n/phonenumbers/demo.js

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -58,52 +58,50 @@ function phoneNumberParser() {
5858
output.append('\nResult from isPossibleNumber(): ');
5959
output.append(isPossible);
6060
var validationResult = i18n.phonenumbers.PhoneNumberUtil.ValidationResult;
61-
var isPossibleReason = phoneUtil_.isPossibleNumberWithReason(number)
62-
var hasRegionCode = regionCode && regionCode != 'ZZ';
63-
if (isPossible) {
64-
// Checking as isValid() fails if possible local only.
65-
if (isPossibleReason == validationResult.IS_POSSIBLE_LOCAL_ONLY) {
66-
output.append('\nResult from isPossibleNumberWithReason(): ');
61+
var isPossibleReason = phoneUtil_.isPossibleNumberWithReason(number);
62+
output.append('\nResult from isPossibleNumberWithReason(): ');
63+
switch (isPossibleReason) {
64+
case validationResult.IS_POSSIBLE:
65+
output.append('IS_POSSIBLE');
66+
break;
67+
case validationResult.IS_POSSIBLE_LOCAL_ONLY:
6768
output.append('IS_POSSIBLE_LOCAL_ONLY');
69+
break;
70+
case validationResult.INVALID_COUNTRY_CODE:
71+
output.append('INVALID_COUNTRY_CODE');
72+
break;
73+
case validationResult.TOO_SHORT:
74+
output.append('TOO_SHORT');
75+
break;
76+
case validationResult.TOO_LONG:
77+
output.append('TOO_LONG');
78+
break;
79+
case validationResult.INVALID_LENGTH:
80+
output.append('INVALID_LENGTH');
81+
break;
82+
}
83+
var hasRegionCode = regionCode && regionCode != 'ZZ';
84+
var isNumberValid = phoneUtil_.isValidNumber(number);
85+
output.append('\nResult from isValidNumber(): ');
86+
output.append(isNumberValid);
87+
if (isNumberValid) {
88+
if (isPossibleReason != validationResult.IS_POSSIBLE) {
6889
output.append(
69-
'\nNumber is considered invalid as it is ' +
70-
'not a possible national number.');
71-
} else {
72-
var isNumberValid = phoneUtil_.isValidNumber(number);
73-
output.append('\nResult from isValidNumber(): ');
74-
output.append(isNumberValid);
75-
if (isNumberValid && hasRegionCode) {
90+
'\nWarning: This number represents a known edge case - it is ' +
91+
'a valid number, but it is not considered (strictly) possible. ' +
92+
'See https://issuetracker.google.com/issues/335892662 for more details.');
93+
}
94+
if (hasRegionCode) {
7695
output.append('\nResult from isValidNumberForRegion(): ');
7796
output.append(phoneUtil_.isValidNumberForRegion(number, regionCode));
78-
}
79-
output.append('\nPhone Number region: ');
80-
output.append(phoneUtil_.getRegionCodeForNumber(number));
81-
output.append('\nResult from getNumberType(): ');
82-
output.append(getNumberTypeString(number));
8397
}
98+
output.append('\nPhone Number region: ');
99+
output.append(phoneUtil_.getRegionCodeForNumber(number));
100+
output.append('\nResult from getNumberType(): ');
101+
output.append(getNumberTypeString(number));
84102
} else {
85-
output.append('\nResult from isPossibleNumberWithReason(): ');
86-
switch (isPossibleReason) {
87-
case validationResult.INVALID_COUNTRY_CODE:
88-
output.append('INVALID_COUNTRY_CODE');
89-
break;
90-
case validationResult.TOO_SHORT:
91-
output.append('TOO_SHORT');
92-
break;
93-
case validationResult.TOO_LONG:
94-
output.append('TOO_LONG');
95-
break;
96-
case validationResult.INVALID_LENGTH:
97-
output.append('INVALID_LENGTH');
98-
break;
99-
}
100-
// IS_POSSIBLE shouldn't happen, since we only call this if _not_
101-
// possible.
102103
output.append(
103-
'\nNote: Numbers that are not possible have type UNKNOWN,' +
104-
' an unknown region, and are considered invalid.');
105-
}
106-
if (!isNumberValid) {
104+
'\nNote: Invalid numbers have type UNKNOWN and no region.');
107105
var shortInfo = i18n.phonenumbers.ShortNumberInfo.getInstance();
108106
output.append('\n\n****ShortNumberInfo Results:****');
109107
output.append('\nResult from isPossibleShortNumber: ');

javascript/i18n/phonenumbers/phonenumberutil.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,6 +3584,12 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.testNumberLengthForType_ =
35843584
* numbers), it will return false for the subscriber-number-only version.
35853585
* </ol>
35863586
*
3587+
* <p>There is a known <a href="https://issuetracker.google.com/issues/335892662">issue</a> with this
3588+
* method: if a number is possible only in a certain region among several regions that share the
3589+
* same country calling code, this method will consider only the "main" region. For example,
3590+
* +1310xxxx are valid numbers in Canada. However, they are not possible in the US. As a result,
3591+
* this method will return IS_POSSIBLE_LOCAL_ONLY for +1310xxxx.
3592+
*
35873593
* @param {i18n.phonenumbers.PhoneNumber} number the number that needs to be
35883594
* checked
35893595
* @return {i18n.phonenumbers.PhoneNumberUtil.ValidationResult} a
@@ -3613,6 +3619,12 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.isPossibleNumberWithReason =
36133619
* numbers), it will return false for the subscriber-number-only version.
36143620
* </ol>
36153621
*
3622+
* <p>There is a known <a href="https://issuetracker.google.com/issues/335892662">issue</a> with this
3623+
* method: if a number is possible only in a certain region among several regions that share the
3624+
* same country calling code, this method will consider only the "main" region. For example,
3625+
* +1310xxxx are valid numbers in Canada. However, they are not possible in the US. As a result,
3626+
* this method will return IS_POSSIBLE_LOCAL_ONLY for +1310xxxx.
3627+
*
36163628
* @param {i18n.phonenumbers.PhoneNumber} number the number that needs to be
36173629
* checked
36183630
* @param {i18n.phonenumbers.PhoneNumberType} type the type we are interested in

0 commit comments

Comments
 (0)