Skip to content
Merged
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
20 changes: 20 additions & 0 deletions csharp/PhoneNumbers.Test/TestPhoneNumberUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,26 @@ public void TestFormatNumberForMobileDialing()
Assert.Equal("+800 1234 5678",
phoneUtil.FormatNumberForMobileDialing(InternationalTollFree, RegionCode.JP, true));

// Dialling a non-geographical number from the non-geographical pseudo-region takes the
// "calling from the number's own region" path, which the cases above skip because JP is
// not 001. International format either way, since non-geographical numbers are always
// internationally diallable.
Assert.Equal("+80012345678",
phoneUtil.FormatNumberForMobileDialing(InternationalTollFree, RegionCode.UN001, false));
Assert.Equal("+800 1234 5678",
phoneUtil.FormatNumberForMobileDialing(InternationalTollFree, RegionCode.UN001, true));

// MX fixed line and mobile numbers dialled from MX: international format, because a
// national-format call needs a carrier code that depends on both parties' local area.
// This is the MX/CL/UZ arm of the same branch, which short-circuit evaluation reaches
// only when the number's region is not the non-geographical one.
Assert.Equal("+52 1 234 567 8900",
phoneUtil.FormatNumberForMobileDialing(MXMobile1, RegionCode.MX, true));
Assert.Equal("+5212345678900",
phoneUtil.FormatNumberForMobileDialing(MXMobile1, RegionCode.MX, false));
Assert.Equal("+52 33 1234 5678",
phoneUtil.FormatNumberForMobileDialing(MXNumber1, RegionCode.MX, true));

// Test that the Australian emergency number 000 is formatted correctly.
var auNumber = new PhoneNumber.Builder()
.SetCountryCode(61)
Expand Down
4 changes: 2 additions & 2 deletions csharp/PhoneNumbers/PhoneNumberUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,23 +1333,23 @@
// For non-geographical countries, and Mexican, Chilean, and Uzbek fixed line and mobile
// numbers, we output international format for numbers that can be dialed internationally as
// that always works.
if (regionCode == REGION_CODE_FOR_NON_GEO_ENTITY
if ((regionCode == REGION_CODE_FOR_NON_GEO_ENTITY
// MX fixed line and mobile numbers should always be formatted in international format,
// even when dialed within MX. For national format to work, a carrier code needs to be
// used, and the correct carrier code depends on if the caller and callee are from the
// same local area. It is trickier to get that to work correctly than using
// international format, which is tested to work fine on all carriers.
// CL fixed line numbers need the national prefix when dialing in the national format,
// but don't have it when used for display. The reverse is true for mobile numbers. As
// a result, we output them in the international format to make it work.
// UZ mobile and fixed-line numbers have to be formatted in international format or
// prefixed with special codes like 03, 04 (for fixed-line) and 05 (for mobile) for
// dialling successfully from mobile devices. As we do not have complete information on
// special codes and to be consistent with formatting across all phone types we return
// the number in international format here.
|| ((regionCode == "MX" || regionCode == "CL"
|| regionCode == "UZ") && isFixedLineOrMobile)
|| regionCode == "UZ") && isFixedLineOrMobile))
&& CanBeInternationallyDialled(numberNoExt))

Check notice

Code scanning / CodeQL

Complex condition Note

Complex condition: too many logical operations in this expression.
{
formattedNumber = Format(numberNoExt, PhoneNumberFormat.INTERNATIONAL);
}
Expand Down