diff --git a/csharp/PhoneNumbers.Test/TestPhoneNumberUtil.cs b/csharp/PhoneNumbers.Test/TestPhoneNumberUtil.cs index c17dd519..d2e365ff 100644 --- a/csharp/PhoneNumbers.Test/TestPhoneNumberUtil.cs +++ b/csharp/PhoneNumbers.Test/TestPhoneNumberUtil.cs @@ -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) diff --git a/csharp/PhoneNumbers/PhoneNumberUtil.cs b/csharp/PhoneNumbers/PhoneNumberUtil.cs index 77820231..236b3424 100644 --- a/csharp/PhoneNumbers/PhoneNumberUtil.cs +++ b/csharp/PhoneNumbers/PhoneNumberUtil.cs @@ -1333,7 +1333,7 @@ public string FormatNumberForMobileDialing(PhoneNumber number, string regionCall // 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 @@ -1348,7 +1348,7 @@ public string FormatNumberForMobileDialing(PhoneNumber number, string regionCall // 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)) { formattedNumber = Format(numberNoExt, PhoneNumberFormat.INTERNATIONAL);