Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/maven/metadata/maven-53c7092088
Browse files Browse the repository at this point in the history
  • Loading branch information
mandlil authored Nov 13, 2024
2 parents 2fff0d8 + d89d07b commit 04e2b35
Show file tree
Hide file tree
Showing 113 changed files with 21,914 additions and 21,465 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/cpp-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow builds and unit tests both main C++ API and also build/data tools for metadata generation.

name: Testing C++ API
on: pull_request
permissions:
contents: read

jobs:
cpp-test:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0

- name: Set up C++ environment
run: |
sudo apt-get install \
cmake cmake-curses-gui libprotobuf-dev libgtest-dev libre2-dev \
libicu-dev libboost-dev libboost-thread-dev libboost-system-dev \
protobuf-compiler
- name: Build C++
run: |
cd cpp
mkdir build
cd build
cmake ..
make
- name: Test C++ Build Tools
run: |
./cpp/build/tools/generate_geocoding_data_test
- name: Test C++ API
run: |
./cpp/build/libphonenumber_test
File renamed without changes.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
!tools/java/cpp-build/target/cpp-build-1.0-SNAPSHOT-jar-with-dependencies.jar
build/
lib/
generated/
generated/
2 changes: 1 addition & 1 deletion FALSEHOODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ surprising how many false assumptions programmers continue to make about them.
countries a leading 0 is significant and forms part of the number itself
(see *A leading zero in numbers formatted for domestic usage can always be
discarded when dialing from abroad*). Moreover, a phone number may contain
other diallable characters (see *Phone numbers contain only digits*) or an
other dialable characters (see *Phone numbers contain only digits*) or an
extension portion, dialled after waiting for a tone.

**Tip:** Use the library to parse and format numbers to handle this
Expand Down
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.45.
Last demo update: v8.13.49.

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
19,363 changes: 9,691 additions & 9,672 deletions cpp/src/phonenumbers/lite_metadata.cc

Large diffs are not rendered by default.

19,918 changes: 9,970 additions & 9,948 deletions cpp/src/phonenumbers/metadata.cc

Large diffs are not rendered by default.

2,735 changes: 1,376 additions & 1,359 deletions cpp/src/phonenumbers/short_metadata.cc

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion java/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@
<arg value="--output-dir=${libphonenumber.test.dir}/com/google/i18n/phonenumbers"/>
<arg value="--data-prefix=data/PhoneNumberMetadataProtoForTesting"/>
<arg value="--mapping-class=CountryCodeToRegionCodeMapForTesting"/>
<arg value="--copyright=2010"/>
<arg value="--copyright=2011"/>
<arg value="--lite-build=false"/>
<arg value="--build-regioncode=true"/>
</exec>
</target>

Expand Down
8 changes: 4 additions & 4 deletions java/carrier/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>carrier</artifactId>
<version>1.230-SNAPSHOT</version>
<version>1.234-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.46-SNAPSHOT</version>
<version>8.13.50-SNAPSHOT</version>
</parent>

<build>
Expand Down Expand Up @@ -79,12 +79,12 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.46-SNAPSHOT</version>
<version>8.13.50-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>prefixmapper</artifactId>
<version>2.240-SNAPSHOT</version>
<version>2.244-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/380_en
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/47_en
Binary file not shown.
Binary file not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/65_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 not shown.
Binary file modified java/carrier/src/com/google/i18n/phonenumbers/carrier/data/995_en
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.46-SNAPSHOT</version>
<version>8.13.50-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.46-SNAPSHOT</version>
<version>8.13.50-SNAPSHOT</version>
</parent>

<properties>
Expand Down Expand Up @@ -68,17 +68,17 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.46-SNAPSHOT</version>
<version>8.13.50-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>geocoder</artifactId>
<version>2.240-SNAPSHOT</version>
<version>2.244-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>carrier</artifactId>
<version>1.230-SNAPSHOT</version>
<version>1.234-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
8 changes: 4 additions & 4 deletions java/geocoder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>geocoder</artifactId>
<version>2.240-SNAPSHOT</version>
<version>2.244-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.46-SNAPSHOT</version>
<version>8.13.50-SNAPSHOT</version>
</parent>

<build>
Expand Down Expand Up @@ -87,12 +87,12 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.46-SNAPSHOT</version>
<version>8.13.50-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>prefixmapper</artifactId>
<version>2.240-SNAPSHOT</version>
<version>2.244-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.
6 changes: 3 additions & 3 deletions java/internal/prefixmapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>prefixmapper</artifactId>
<version>2.240-SNAPSHOT</version>
<version>2.244-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.46-SNAPSHOT</version>
<version>8.13.50-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.46-SNAPSHOT</version>
<version>8.13.50-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions java/libphonenumber/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.46-SNAPSHOT</version>
<version>8.13.50-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.46-SNAPSHOT</version>
<version>8.13.50-SNAPSHOT</version>
</parent>

<build>
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.
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 @@ -16,7 +16,6 @@

package com.google.i18n.phonenumbers.metadata.source;

import java.util.regex.Pattern;

/**
* {@link PhoneMetadataFileNameProvider} implementation which appends key as a suffix to the
Expand All @@ -25,7 +24,6 @@
public final class MultiFileModeFileNameProvider implements PhoneMetadataFileNameProvider {

private final String phoneMetadataFileNamePrefix;
private static final Pattern ALPHANUMERIC = Pattern.compile("^[\\p{L}\\p{N}]+$");

public MultiFileModeFileNameProvider(String phoneMetadataFileNameBase) {
this.phoneMetadataFileNamePrefix = phoneMetadataFileNameBase + "_";
Expand All @@ -34,9 +32,27 @@ public MultiFileModeFileNameProvider(String phoneMetadataFileNameBase) {
@Override
public String getFor(Object key) {
String keyAsString = key.toString();
if (!ALPHANUMERIC.matcher(keyAsString).matches()) {
if (!isAlphanumeric(keyAsString)) {
throw new IllegalArgumentException("Invalid key: " + keyAsString);
}
return phoneMetadataFileNamePrefix + key;
}

private boolean isAlphanumeric(String key) {
if (key == null || key.length() == 0) {
return false;
}
// String#length doesn't actually return the number of
// code points in the String, it returns the number
// of char values.
int size = key.length();
for (int charIdx = 0; charIdx < size; ) {
final int codePoint = key.codePointAt(charIdx);
if (!Character.isLetterOrDigit(codePoint)) {
return false;
}
charIdx += Character.charCount(codePoint);
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 The Libphonenumber Authors
* Copyright (C) 2011 The Libphonenumber Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public void testGetExampleNumber() {
// We have data for the US, but no data for VOICEMAIL, so return null.
assertNull(phoneUtil.getExampleNumberForType(RegionCode.US, PhoneNumberType.VOICEMAIL));
// CS is an invalid region, so we have no data for it.
assertNull(phoneUtil.getExampleNumberForType(RegionCode.CS, PhoneNumberType.MOBILE));
assertNull(phoneUtil.getExampleNumberForType("CS", PhoneNumberType.MOBILE));
// RegionCode 001 is reserved for supporting non-geographical country calling code. We don't
// support getting an example number for it with this method.
assertNull(phoneUtil.getExampleNumber(RegionCode.UN001));
Expand All @@ -425,7 +425,7 @@ public void testGetInvalidExampleNumber() {
// RegionCode 001 is reserved for supporting non-geographical country calling codes. We don't
// support getting an invalid example number for it with getInvalidExampleNumber.
assertNull(phoneUtil.getInvalidExampleNumber(RegionCode.UN001));
assertNull(phoneUtil.getInvalidExampleNumber(RegionCode.CS));
assertNull(phoneUtil.getInvalidExampleNumber("CS"));
PhoneNumber usInvalidNumber = phoneUtil.getInvalidExampleNumber(RegionCode.US);
assertEquals(1, usInvalidNumber.getCountryCode());
assertFalse(usInvalidNumber.getNationalNumber() == 0);
Expand Down Expand Up @@ -658,7 +658,7 @@ public void testFormatOutOfCountryWithInvalidRegion() {
// AQ/Antarctica isn't a valid region code for phone number formatting,
// so this falls back to intl formatting.
assertEquals("+1 650 253 0000",
phoneUtil.formatOutOfCountryCallingNumber(US_NUMBER, RegionCode.AQ));
phoneUtil.formatOutOfCountryCallingNumber(US_NUMBER, "AQ"));
// For region code 001, the out-of-country format always turns into the international format.
assertEquals("+1 650 253 0000",
phoneUtil.formatOutOfCountryCallingNumber(US_NUMBER, RegionCode.UN001));
Expand Down Expand Up @@ -735,7 +735,7 @@ public void testFormatOutOfCountryKeepingAlphaChars() {
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.SG));
// Testing the case of calling from a non-supported region.
assertEquals("+61 1-800-SIX-FLAG",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AQ));
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, "AQ"));

// Testing the case with an invalid country calling code.
alphaNumericNumber.setCountryCode(0).setNationalNumber(18007493524L)
Expand All @@ -754,7 +754,7 @@ public void testFormatOutOfCountryKeepingAlphaChars() {
alphaNumericNumber.setCountryCode(1).setNationalNumber(80749L).setRawInput("180-SIX");
// No country-code stripping can be done since the number is invalid.
assertEquals("+1 180-SIX",
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, RegionCode.AQ));
phoneUtil.formatOutOfCountryKeepingAlphaChars(alphaNumericNumber, "AQ"));
}

public void testFormatWithCarrierCode() {
Expand Down Expand Up @@ -820,12 +820,12 @@ public void testFormatNumberForMobileDialing() {
assertEquals("030123456",
phoneUtil.formatNumberForMobileDialing(DE_NUMBER, RegionCode.DE, false));
assertEquals("+4930123456",
phoneUtil.formatNumberForMobileDialing(DE_NUMBER, RegionCode.CH, false));
phoneUtil.formatNumberForMobileDialing(DE_NUMBER, "CH", false));
PhoneNumber deNumberWithExtn = new PhoneNumber().mergeFrom(DE_NUMBER).setExtension("1234");
assertEquals("030123456",
phoneUtil.formatNumberForMobileDialing(deNumberWithExtn, RegionCode.DE, false));
assertEquals("+4930123456",
phoneUtil.formatNumberForMobileDialing(deNumberWithExtn, RegionCode.CH, false));
phoneUtil.formatNumberForMobileDialing(deNumberWithExtn, "CH", false));

// US toll free numbers are marked as noInternationalDialling in the test metadata for testing
// purposes. For such numbers, we expect nothing to be returned when the region code is not the
Expand Down Expand Up @@ -1336,7 +1336,7 @@ public void testGetCountryCodeForRegion() {
assertEquals(0, phoneUtil.getCountryCodeForRegion(RegionCode.ZZ));
assertEquals(0, phoneUtil.getCountryCodeForRegion(RegionCode.UN001));
// CS is already deprecated so the library doesn't support it.
assertEquals(0, phoneUtil.getCountryCodeForRegion(RegionCode.CS));
assertEquals(0, phoneUtil.getCountryCodeForRegion("CS"));
}

public void testGetNationalDiallingPrefixForRegion() {
Expand All @@ -1353,7 +1353,7 @@ public void testGetNationalDiallingPrefixForRegion() {
assertEquals(null, phoneUtil.getNddPrefixForRegion(RegionCode.ZZ, false));
assertEquals(null, phoneUtil.getNddPrefixForRegion(RegionCode.UN001, false));
// CS is already deprecated so the library doesn't support it.
assertEquals(null, phoneUtil.getNddPrefixForRegion(RegionCode.CS, false));
assertEquals(null, phoneUtil.getNddPrefixForRegion("CS", false));
}

public void testIsNANPACountry() {
Expand Down Expand Up @@ -2430,7 +2430,7 @@ public void testFailedParseOnInvalidNumbers() {
}
try {
String someNumber = "123 456 7890";
phoneUtil.parse(someNumber, RegionCode.CS);
phoneUtil.parse(someNumber, "CS");
fail("Deprecated region code not allowed: should fail.");
} catch (NumberParseException e) {
// Expected this exception.
Expand Down Expand Up @@ -2854,7 +2854,7 @@ public void testParseAndKeepRaw() throws Exception {

// Invalid region code supplied.
try {
phoneUtil.parseAndKeepRawInput("123 456 7890", RegionCode.CS);
phoneUtil.parseAndKeepRawInput("123 456 7890", "CS");
fail("Deprecated region code not allowed: should fail.");
} catch (NumberParseException e) {
// Expected this exception.
Expand Down
Loading

0 comments on commit 04e2b35

Please sign in to comment.