Skip to content

Commit

Permalink
Merge branch 'google:master' into rename-nongeographicalregion
Browse files Browse the repository at this point in the history
  • Loading branch information
KarolJakubKrawiec authored Jan 29, 2025
2 parents 75c58a8 + f0e422d commit 7fc605d
Show file tree
Hide file tree
Showing 110 changed files with 19,800 additions and 19,751 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/osv-scanner-unified.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
scan-scheduled:
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
# If you want to copy this config, highly suggest pinning this version to a release rather than tracking the main branch
uses: google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@8bd1ce1c4be9d98053ffd9e6e14585276a36762c" # v1.9.1
uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@8bd1ce1c4be9d98053ffd9e6e14585276a36762c" # v1.9.1
with:
# Just scan the root directory and docs, since everything else is fixtures
scan-args: |-
Expand All @@ -45,7 +45,7 @@ jobs:
scan-pr:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'merge_group' }}
# If you want to copy this config, highly suggest pinning this version to a release rather than tracking the main branch
uses: google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml@8bd1ce1c4be9d98053ffd9e6e14585276a36762c" # v1.9.1
uses: "google/osv-scanner-action/.github/workflows/osv-scanner-reusable-pr.yml@8bd1ce1c4be9d98053ffd9e6e14585276a36762c" # v1.9.1
with:
# Just scan the root directory and docs, since everything else is fixtures
scan-args: |-
Expand Down
19 changes: 14 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
target/
!tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar
build/
lib/
generated/
# Ignore build directories and any files generated by the update script.
cpp/build/
cpp/src/phonenumbers/geocoding/geocoding_data.cc
cpp/src/phonenumbers/phonemetadata.pb.*
cpp/src/phonenumbers/phonenumber.pb.*
cpp/test/phonenumbers/geocoding/geocoding_test_data.cc
java/build/
java/demo/war/WEB-INF/classes/
java/demo/war/WEB-INF/lib/
java/**/target/
# Ignore the logs directory
/logs/
# Ignore ourselves because this is not intended to be submitted.
/.gitignore
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Cream Sandwich).
The [Java demo](https://libphonenumber.appspot.com/) is updated with a slight
delay after the GitHub release.

Last demo update: v8.13.51.
Last demo update: v8.13.53.

Note: Even though the library (main branch/[maven release](https://repo1.maven.org/maven2/com/googlecode/libphonenumber/libphonenumber/8.12.56/))
is at v8.12.57, because of some deployment issues, we were unable to update the
Expand Down
18,638 changes: 9,319 additions & 9,319 deletions cpp/src/phonenumbers/lite_metadata.cc

Large diffs are not rendered by default.

19,812 changes: 9,906 additions & 9,906 deletions cpp/src/phonenumbers/metadata.cc

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions cpp/src/phonenumbers/phonenumberutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,17 @@ void PhoneNumberUtil::FormatOutOfCountryKeepingAlphaChars(
PrefixNumberWithCountryCallingCode(country_code, INTERNATIONAL,
formatted_number);
}
std::string region_code;
GetRegionCodeForCountryCode(country_code, &region_code);
// Metadata cannot be null because the country code is valid.
const PhoneMetadata* metadata_for_region =
GetMetadataForRegionOrCallingCode(country_code, region_code);
// Strip any extension
std::string extension;
MaybeStripExtension(formatted_number, &extension);
// Append the formatted extension
MaybeAppendFormattedExtension(number, *metadata_for_region, INTERNATIONAL,
formatted_number);
}

const NumberFormat* PhoneNumberUtil::ChooseFormattingPatternForNumber(
Expand Down
14 changes: 14 additions & 0 deletions cpp/src/phonenumbers/phonenumberutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,13 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// would most likely be area codes) and length (obviously includes the
// length of area codes for fixed line numbers), it will return false for
// the subscriber-number-only version.
//
// There is a known issue with this method: if a number is possible only in a
// certain region among several regions that share the same country calling
// code, this method will consider only the "main" region. For example,
// +1310xxxx are valid numbers in Canada. However, they are not possible in
// the US. As a result, this method will return false for +1310xxxx. See
// https://issuetracker.google.com/issues/335892662 for more details.
ValidationResult IsPossibleNumberWithReason(const PhoneNumber& number) const;

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

Expand Down
10 changes: 10 additions & 0 deletions cpp/test/phonenumbers/phonenumberutil_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,16 @@ TEST_F(PhoneNumberUtilTest, FormatOutOfCountryKeepingAlphaChars) {
&formatted_number);
EXPECT_EQ("1 800 SIX-FLAG", formatted_number);

// Testing a number with extension.
formatted_number.clear();
PhoneNumber alpha_numeric_number_with_extn;
phone_util_.ParseAndKeepRawInput("800 SIX-flag ext. 1234", RegionCode::US(),
&alpha_numeric_number_with_extn);
// preferredExtnPrefix for US is " extn. " (in test metadata)
phone_util_.FormatOutOfCountryKeepingAlphaChars(
alpha_numeric_number_with_extn, RegionCode::AU(), &formatted_number);
EXPECT_EQ("0011 1 800 SIX-FLAG extn. 1234", formatted_number);

// Testing that if the raw input doesn't exist, it is formatted using
// FormatOutOfCountryCallingNumber.
alpha_numeric_number.clear_raw_input();
Expand Down
12 changes: 5 additions & 7 deletions java/carrier/pom.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>carrier</artifactId>
<version>1.236-SNAPSHOT</version>
<version>1.238-SNAPSHOT</version>
<packaging>jar</packaging>
<url>https://github.com/google/libphonenumber/</url>

<parent>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber-parent</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
</parent>

<build>
Expand Down Expand Up @@ -83,12 +81,12 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>prefixmapper</artifactId>
<version>2.246-SNAPSHOT</version>
<version>2.248-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/351_en
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/41_en
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/48_en
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/51_en
Binary file not shown.
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/680_en
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/852_en
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/852_zh
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/90_en
Binary file not shown.
Binary file not shown.
10 changes: 5 additions & 5 deletions java/demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>demo</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
<packaging>war</packaging>
<url>https://github.com/google/libphonenumber/</url>
<parent>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber-parent</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
</parent>

<properties>
Expand Down Expand Up @@ -68,17 +68,17 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>geocoder</artifactId>
<version>2.246-SNAPSHOT</version>
<version>2.248-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>carrier</artifactId>
<version>1.236-SNAPSHOT</version>
<version>1.238-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,44 +101,42 @@
<TH>Result from isPossibleNumber()</TH>
<TD>{$isPossibleNumber}</TD>
</TR>
{if $isPossibleNumber}
{if $validationResult == "IS_POSSIBLE_LOCAL_ONLY"}
<TR>
<TH>Result from isPossibleNumberWithReason()</TH>
<TD>{$validationResult}</TD>
</TR>
<TR>
<TD colspan=2>Number is considered invalid as it is not a possible national number.</TD>
</TR>
{else}
<TR>
<TH>Result from isValidNumber()</TH>
<TD>{$isValidNumber}</TD>
</TR>
{if $isValidNumber}
{if $validationResult != "IS_POSSIBLE"}
<TR>
<TD colspan=2 style="color:red">
Warning: This number represents a known <a href="https://issuetracker.google.com/issues/335892662">
edge case</a> - it is a valid number, but it is not considered (strictly) possible
</TD>
</TR>
{/if}
{if $isValidNumberForRegion != null}
<TR>
<TH>Result from isValidNumberForRegion()</TH>
<TD>{$isValidNumberForRegion}</TD>
</TR>
<TR>
<TH>Result from isValidNumberForRegion()</TH>
<TD>{$isValidNumberForRegion}</TD>
</TR>
{/if}
<TR>
<TH>Phone Number region</TH>
<TD>{$phoneNumberRegion ?: ""}</TD>
<TD>{$phoneNumberRegion}</TD>
</TR>
<TR>
<TH>Result from getNumberType()</TH>
<TD>{$numberType}</TD>
</TR>
{/if}
{else}
<TR>
<TH>Result from isPossibleNumberWithReason()</TH>
<TD>{$validationResult}</TD>
</TR>
<TR>
<TD colspan=2>Note: Numbers that are not possible have type UNKNOWN, an unknown region, and are considered invalid.</TD>
</TR>
{/if}
{else}
<TR>
<TD colspan=2>Note: Invalid numbers have type UNKNOWN and no region.</TD>
</TR>
{/if}
</TABLE>
</DIV>

Expand Down
12 changes: 5 additions & 7 deletions java/geocoder/pom.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>geocoder</artifactId>
<version>2.246-SNAPSHOT</version>
<version>2.248-SNAPSHOT</version>
<packaging>jar</packaging>
<url>https://github.com/google/libphonenumber/</url>

<parent>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber-parent</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
</parent>

<build>
Expand Down Expand Up @@ -93,12 +91,12 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>prefixmapper</artifactId>
<version>2.246-SNAPSHOT</version>
<version>2.248-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 4 additions & 6 deletions java/internal/prefixmapper/pom.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>prefixmapper</artifactId>
<version>2.246-SNAPSHOT</version>
<version>2.248-SNAPSHOT</version>
<packaging>jar</packaging>
<url>https://github.com/google/libphonenumber/</url>

<parent>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber-parent</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -85,7 +83,7 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
8 changes: 3 additions & 5 deletions java/libphonenumber/pom.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>libphonenumber</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
<packaging>jar</packaging>
<url>https://github.com/google/libphonenumber/</url>

<parent>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber-parent</artifactId>
<version>8.13.52-SNAPSHOT</version>
<version>8.13.54-SNAPSHOT</version>
</parent>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1878,8 +1878,11 @@ public String formatOutOfCountryKeepingAlphaChars(PhoneNumber number,
String regionCode = getRegionCodeForCountryCode(countryCode);
// Metadata cannot be null because the country calling code is valid.
PhoneMetadata metadataForRegion = getMetadataForRegionOrCallingCode(countryCode, regionCode);
maybeAppendFormattedExtension(number, metadataForRegion,
PhoneNumberFormat.INTERNATIONAL, formattedNumber);
// Strip any extension
maybeStripExtension(formattedNumber);
// Append the formatted extension
maybeAppendFormattedExtension(
number, metadataForRegion, PhoneNumberFormat.INTERNATIONAL, formattedNumber);
if (internationalPrefixForFormatting.length() > 0) {
formattedNumber.insert(0, " ").insert(0, countryCode).insert(0, " ")
.insert(0, internationalPrefixForFormatting);
Expand Down Expand Up @@ -2713,6 +2716,13 @@ private ValidationResult testNumberLength(
* length (obviously includes the length of area codes for fixed line numbers), it will
* return false for the subscriber-number-only version.
* </ol>
*
* <p>There is a known <a href="https://issuetracker.google.com/issues/335892662">issue</a> with this
* method: if a number is possible only in a certain region among several regions that share the
* same country calling code, this method will consider only the "main" region. For example,
* +1310xxxx are valid numbers in Canada. However, they are not possible in the US. As a result,
* this method will return IS_POSSIBLE_LOCAL_ONLY for +1310xxxx.
*
* @param number the number that needs to be checked
* @return a ValidationResult object which indicates whether the number is possible
*/
Expand Down Expand Up @@ -2742,6 +2752,12 @@ public ValidationResult isPossibleNumberWithReason(PhoneNumber number) {
* return false for the subscriber-number-only version.
* </ol>
*
* <p>There is a known <a href="https://issuetracker.google.com/issues/335892662">issue</a> with this
* method: if a number is possible only in a certain region among several regions that share the
* same country calling code, this method will consider only the "main" region. For example,
* +1310xxxx are valid numbers in Canada. However, they are not possible in the US. As a result,
* this method will return IS_POSSIBLE_LOCAL_ONLY for +1310xxxx.
*
* @param number the number that needs to be checked
* @param type the type we are interested in
* @return a ValidationResult object which indicates whether the number is possible
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ public void testFormatOutOfCountryWithPreferredIntlPrefix() {
phoneUtil.formatOutOfCountryCallingNumber(IT_NUMBER, RegionCode.UZ));
}

public void testFormatOutOfCountryKeepingAlphaChars() {
public void testFormatOutOfCountryKeepingAlphaChars() throws Exception {
PhoneNumber alphaNumericNumber = new PhoneNumber();
alphaNumericNumber.setCountryCode(1).setNationalNumber(8007493524L)
.setRawInput("1800 six-flag");
Expand All @@ -701,6 +701,13 @@ public void testFormatOutOfCountryKeepingAlphaChars() {
assertEquals("1 800 SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.BS));

// Testing a number with extension.
PhoneNumber alphaNumericNumberWithExtn =
phoneUtil.parseAndKeepRawInput("800 SIX-flag ext. 1234", RegionCode.US);
assertEquals(
"0011 1 800 SIX-FLAG extn. 1234",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumberWithExtn, RegionCode.AU));

// Testing that if the raw input doesn't exist, it is formatted using
// formatOutOfCountryCallingNumber.
alphaNumericNumber.clearRawInput();
Expand Down
Loading

0 comments on commit 7fc605d

Please sign in to comment.