Browse Source

Merge branch 'master' into dependabot/maven/java/demo/maven-1b7e7d95da

pull/3664/head
mandlil 8 months ago
committed by GitHub
parent
commit
d898bf78a6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
323 changed files with 37842 additions and 37290 deletions
  1. +1
    -1
      .github/workflows/codeql.yml
  2. +54
    -0
      .github/workflows/osv-scanner-unified.yml
  3. +1
    -1
      FALSEHOODS.md
  4. +1
    -12
      FAQ.md
  5. +1
    -1
      README.md
  6. +1
    -1
      cpp/CMakeLists.txt
  7. +1229
    -1226
      cpp/src/phonenumbers/alternate_format.cc
  8. +1
    -1
      cpp/src/phonenumbers/asyoutypeformatter.h
  9. +13183
    -13137
      cpp/src/phonenumbers/lite_metadata.cc
  10. +14315
    -14269
      cpp/src/phonenumbers/metadata.cc
  11. +257
    -227
      cpp/src/phonenumbers/phonenumberutil.cc
  12. +143
    -113
      cpp/src/phonenumbers/phonenumberutil.h
  13. +3452
    -3445
      cpp/src/phonenumbers/short_metadata.cc
  14. +1
    -5
      cpp/src/phonenumbers/stringutil.cc
  15. +4
    -5
      cpp/src/phonenumbers/stringutil.h
  16. +64
    -0
      cpp/test/phonenumbers/fuzz_asyoutypeformatter.cc
  17. +85
    -0
      cpp/test/phonenumbers/fuzz_matcher.cc
  18. +175
    -14
      cpp/test/phonenumbers/fuzz_phone.cc
  19. +79
    -0
      cpp/test/phonenumbers/fuzz_shortnumberinfo.cc
  20. +10
    -0
      cpp/test/phonenumbers/phonenumberutil_test.cc
  21. +14
    -12
      java/carrier/pom.xml
  22. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1671_en
  23. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/212_en
  24. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/221_en
  25. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/223_en
  26. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/228_en
  27. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/229_en
  28. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/252_en
  29. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/255_en
  30. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/256_en
  31. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/260_en
  32. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/262_en
  33. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/268_en
  34. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/27_en
  35. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/33_en
  36. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/34_en
  37. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/351_en
  38. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/36_en
  39. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/371_en
  40. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/385_en
  41. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/389_en
  42. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/41_en
  43. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/43_en
  44. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/45_en
  45. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/48_en
  46. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/503_en
  47. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/508_en
  48. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/51_en
  49. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/58_en
  50. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/590_en
  51. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/592_en
  52. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/594_en
  53. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/596_en
  54. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/597_en
  55. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/65_en
  56. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/674_en
  57. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/680_en
  58. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/81_en
  59. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/852_en
  60. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/852_zh
  61. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/855_en
  62. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/90_en
  63. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/92_en
  64. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/963_en
  65. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/972_en
  66. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/976_en
  67. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/992_en
  68. BIN
      java/carrier/src/com/google/i18n/phonenumbers/carrier/data/995_en
  69. +7
    -7
      java/demo/pom.xml
  70. +19
    -21
      java/demo/src/main/resources/com/google/phonenumbers/demo/result.soy
  71. +1
    -1
      java/demo/src/main/webapp/WEB-INF/appengine-web.xml
  72. +18
    -14
      java/geocoder/pom.xml
  73. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1274_en
  74. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1327_en
  75. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1345_en
  76. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1821_en
  77. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1942_en
  78. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/372_en
  79. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/52_en
  80. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_en
  81. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_zh
  82. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/config
  83. BIN
      java/geocoder/src/com/google/i18n/phonenumbers/timezones/data/map_data
  84. +19
    -11
      java/internal/prefixmapper/pom.xml
  85. +19
    -7
      java/libphonenumber/pom.xml
  86. +18
    -2
      java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
  87. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberAlternateFormatsProto_385
  88. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberAlternateFormatsProto_43
  89. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_870
  90. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR
  91. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AT
  92. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BE
  93. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BJ
  94. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BL
  95. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CA
  96. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CZ
  97. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE
  98. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DK
  99. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EH
  100. BIN
      java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FI

+ 1
- 1
.github/workflows/codeql.yml View File

@ -49,7 +49,7 @@ jobs:
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
- name: Install Protoc
uses: arduino/setup-protoc@v1
uses: arduino/setup-protoc@149f6c87b92550901b26acd1632e11c3662e381f # v1.3.0
with:
version: '3.x'


+ 54
- 0
.github/workflows/osv-scanner-unified.yml View File

@ -0,0 +1,54 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: OSV-Scanner
on:
pull_request:
branches: ["master"]
schedule:
- cron: "12 12 * * 1"
push:
branches: ["master"]
permissions:
# Required to upload SARIF file to CodeQL. See: https://github.com/github/codeql-action/issues/2117
actions: read
# Require writing security events to upload SARIF file to security tab
security-events: write
# Read commit contents
contents: read
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
with:
# Just scan the root directory and docs, since everything else is fixtures
scan-args: |-
-r
--skip-git
./
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
with:
# Just scan the root directory and docs, since everything else is fixtures
scan-args: |-
-r
--skip-git
./

+ 1
- 1
FALSEHOODS.md View File

@ -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


+ 1
- 12
FAQ.md View File

@ -362,20 +362,9 @@ right thing if the phone number object is as intended.
@Mexico,
Mexico used to have such additional prefixes (1, 02, 045, ...) for dialling
mobile numbers internationally, fixed-line to mobile nationally.. As these
dialling patterns were deprecated, we have continued to maintain mobile and
dialling patterns were deprecated, we removed them but still maintain mobile and
fixed-line ranges at higher level, returning type as [`FIXED_LINE_OR_MOBILE`](#fixed_line_or_mobile)
### <a href="#mx_legacy_formats">Why Mexico (MX) numbers in older dialling formats are accepted as valid ones?</a>
Though library has stopped supporting below older dialling codes in the canonical
form and formatting results, we are lenient in parsing the number, i.e removing
all older codes.
- 1 -> in E.164 international diallings
- 01, 02, 044 and 045 -> for local/national diallings
This is because we found the older dialling codes supported even after deprecation
period, so we decided to support them for longer time. However, we will stop this as
part of [this issue](https://issuetracker.google.com/issues/205606725). More details there.
### <a name="#unsupported_regions">Why are Bouvet Island (BV), Pitcairn Island (PN), Antarctica (AQ) etc. not supported?</a>
We only support a country if:


+ 1
- 1
README.md View File

@ -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.49.
Last demo update: v9.0.3.
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


+ 1
- 1
cpp/CMakeLists.txt View File

@ -16,7 +16,7 @@
cmake_minimum_required (VERSION 3.11)
project (libphonenumber VERSION 8.13.0)
project (libphonenumber VERSION 9.0.0)
if (32BIT)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")


+ 1229
- 1226
cpp/src/phonenumbers/alternate_format.cc
File diff suppressed because it is too large
View File


+ 1
- 1
cpp/src/phonenumbers/asyoutypeformatter.h View File

@ -129,7 +129,7 @@ class AsYouTypeFormatter {
// Check to see if there is an exact pattern match for these digits. If so, we
// should use this instead of any other formatting template whose
// leadingDigitsPattern also matches the input.
void AttemptToFormatAccruedDigits(string* formatted_number);
void AttemptToFormatAccruedDigits(string* formatted_result);
// Combines the national number with any prefix (IDD/+ and country code or
// national prefix) that was collected. A space will be inserted between them


+ 13183
- 13137
cpp/src/phonenumbers/lite_metadata.cc
File diff suppressed because it is too large
View File


+ 14315
- 14269
cpp/src/phonenumbers/metadata.cc
File diff suppressed because it is too large
View File


+ 257
- 227
cpp/src/phonenumbers/phonenumberutil.cc
File diff suppressed because it is too large
View File


+ 143
- 113
cpp/src/phonenumbers/phonenumberutil.h View File

@ -32,7 +32,6 @@
#include "absl/container/node_hash_set.h"
#include "absl/container/node_hash_map.h"
#include "absl/strings/string_view.h"
class TelephoneNumber;
@ -40,6 +39,7 @@ namespace i18n {
namespace phonenumbers {
using google::protobuf::RepeatedPtrField;
using std::string;
class AsYouTypeFormatter;
class Logger;
@ -181,7 +181,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// @returns an unordered set of the two-letter region codes for every
// geographical region the library supports
void GetSupportedRegions(
std::set<std::string>* regions) const;
std::set<string>* regions) const;
// Returns all global network calling codes the library has metadata for.
// @returns an unordered set of the country calling codes for every
@ -202,7 +202,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
//
// No types will be returned for invalid or unknown region codes.
void GetSupportedTypesForRegion(
const std::string& region_code,
const string& region_code,
std::set<PhoneNumberType>* types) const;
// Returns the types for a country-code belonging to a non-geographical entity
@ -232,26 +232,26 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// checks - to work out if this number is actually valid for a region, it
// should be parsed and methods such as IsPossibleNumberWithReason or
// IsValidNumber should be used.
bool IsAlphaNumber(const std::string& number) const;
bool IsAlphaNumber(const string& number) const;
// Converts all alpha characters in a number to their respective digits on
// a keypad, but retains existing formatting.
void ConvertAlphaCharactersInNumber(std::string* number) const;
void ConvertAlphaCharactersInNumber(string* number) const;
// Normalizes a string of characters representing a phone number. This
// converts wide-ascii and arabic-indic numerals to European numerals, and
// strips punctuation and alpha characters.
void NormalizeDigitsOnly(std::string* number) const;
void NormalizeDigitsOnly(string* number) const;
// Normalizes a string of characters representing a phone number. This strips
// all characters which are not diallable on a mobile phone keypad (including
// all non-ASCII digits).
void NormalizeDiallableCharsOnly(std::string* number) const;
void NormalizeDiallableCharsOnly(string* number) const;
// Gets the national significant number of a phone number. Note a national
// significant number doesn't contain a national prefix or any formatting.
void GetNationalSignificantNumber(
const PhoneNumber& number, std::string* national_significant_num) const;
void GetNationalSignificantNumber(const PhoneNumber& number,
string* national_number) const;
// Gets the length of the geographical area code from the PhoneNumber object
// passed in, so that clients could use it to split a national significant
@ -335,7 +335,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// before the area code when dialing a mobile number from that country from
// abroad.
void GetCountryMobileToken(int country_calling_code,
std::string* mobile_token) const;
string* mobile_token) const;
// Formats a phone number in the specified format using default rules. Note
// that this does not promise to produce a phone number that the user can
@ -343,15 +343,17 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// INTERNATIONAL format depending on what the client asks for, we do not
// currently support a more abbreviated format, such as for users in the
// same area who could potentially dial the number without area code.
void Format(const PhoneNumber& number, PhoneNumberFormat number_format,
std::string* formatted_number) const;
void Format(const PhoneNumber& number,
PhoneNumberFormat number_format,
string* formatted_number) const;
// Formats a phone number in the specified format using client-defined
// formatting rules.
void FormatByPattern(
const PhoneNumber& number, PhoneNumberFormat number_format,
const PhoneNumber& number,
PhoneNumberFormat number_format,
const RepeatedPtrField<NumberFormat>& user_defined_formats,
std::string* formatted_number) const;
string* formatted_number) const;
// Formats a phone number in national format for dialing using the carrier as
// specified in the carrier_code. The carrier_code will always be used
@ -359,8 +361,8 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// carrier code stored. If carrier_code contains an empty string, return the
// number in national format without any carrier code.
void FormatNationalNumberWithCarrierCode(const PhoneNumber& number,
const std::string& carrier_code,
std::string* formatted_number) const;
const string& carrier_code,
string* formatted_number) const;
// Formats a phone number in national format for dialing using the carrier as
// specified in the preferred_domestic_carrier_code field of the PhoneNumber
@ -373,8 +375,9 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// in should take precedence over the number's preferred_domestic_carrier_code
// when formatting.
void FormatNationalNumberWithPreferredCarrierCode(
const PhoneNumber& number, const std::string& fallback_carrier_code,
std::string* formatted_number) const;
const PhoneNumber& number,
const string& fallback_carrier_code,
string* formatted_number) const;
// Returns a number formatted in such a way that it can be dialed from a
// mobile phone in a specific region. If the number cannot be reached from
@ -382,8 +385,9 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// outside of the country), the method returns an empty string.
void FormatNumberForMobileDialing(
const PhoneNumber& number,
const std::string& region_calling_from, bool with_formatting,
std::string* formatted_number) const;
const string& region_calling_from,
bool with_formatting,
string* formatted_number) const;
// Formats a phone number for out-of-country dialing purposes.
//
@ -393,8 +397,9 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// have multiple international prefixes, the number in its INTERNATIONAL
// format will be returned instead.
void FormatOutOfCountryCallingNumber(
const PhoneNumber& number, const std::string& calling_from,
std::string* formatted_number) const;
const PhoneNumber& number,
const string& calling_from,
string* formatted_number) const;
// Formats a phone number using the original phone number format (e.g.
// INTERNATIONAL or NATIONAL) that the number is parsed from, provided that
@ -406,8 +411,8 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// When the number is an invalid number, the method returns the raw input when
// it is available.
void FormatInOriginalFormat(const PhoneNumber& number,
const std::string& region_calling_from,
std::string* formatted_number) const;
const string& region_calling_from,
string* formatted_number) const;
// Formats a phone number for out-of-country dialing purposes.
//
@ -427,8 +432,9 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// before these digits. Normally people group the first three digits together
// so this is not a huge problem - and will be fixed if it proves to be so.
void FormatOutOfCountryKeepingAlphaChars(
const PhoneNumber& number, const std::string& calling_from,
std::string* formatted_number) const;
const PhoneNumber& number,
const string& calling_from,
string* formatted_number) const;
// Attempts to extract a valid number from a phone number that is too long to
// be valid, and resets the PhoneNumber object passed in to that valid
@ -465,17 +471,17 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// since it has its own region code, "IM", which may be undesirable.
bool IsValidNumberForRegion(
const PhoneNumber& number,
const std::string& region_code) const;
const string& region_code) const;
// Returns the region where a phone number is from. This could be used for
// geocoding at the region level. Only guarantees correct results for valid,
// full numbers (not short-codes, or invalid numbers).
void GetRegionCodeForNumber(const PhoneNumber& number,
std::string* region_code) const;
string* region_code) const;
// Returns the country calling code for a specific region. For example,
// this would be 1 for the United States, and 64 for New Zealand.
int GetCountryCodeForRegion(const std::string& region_code) const;
int GetCountryCodeForRegion(const string& region_code) const;
// Returns the region code that matches the specific country code. Note that
// it is possible that several regions share the same country calling code
@ -485,7 +491,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// (such as in the case of non-geographical calling codes like 800) the
// RegionCode 001 will be returned (corresponding to the value for World in
// the UN M.49 schema).
void GetRegionCodeForCountryCode(int country_code, std::string* region_code) const;
void GetRegionCodeForCountryCode(int country_code, string* region_code) const;
// Populates a list with the region codes that match the specific country
// calling code. For non-geographical country calling codes, the region code
@ -493,20 +499,20 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// is left unchanged.
void GetRegionCodesForCountryCallingCode(
int country_calling_code,
std::list<std::string>* region_codes) const;
std::list<string>* region_codes) const;
// Checks if this is a region under the North American Numbering Plan
// Administration (NANPA).
bool IsNANPACountry(const std::string& region_code) const;
bool IsNANPACountry(const string& region_code) const;
// Returns the national dialling prefix for a specific region. For example,
// this would be 1 for the United States, and 0 for New Zealand. Set
// strip_non_digits to true to strip symbols like "~" (which indicates a wait
// for a dialling tone) from the prefix returned. If no national prefix is
// present, we return an empty string.
void GetNddPrefixForRegion(const std::string& region_code,
void GetNddPrefixForRegion(const string& region_code,
bool strip_non_digits,
std::string* national_prefix) const;
string* national_prefix) const;
// Checks whether a phone number is a possible number. It provides a more
// lenient check than IsValidNumber() in the following sense:
@ -525,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
@ -559,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;
@ -592,8 +612,8 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// as 253 0000, it could only be dialed from within a smaller area in the US
// (Mountain View, CA, to be more specific).
bool IsPossibleNumberForString(
absl::string_view number,
const std::string& region_dialing_from) const;
const string& number,
const string& region_dialing_from) const;
// Returns true if the number can be dialled from outside the region, or
// unknown. If the number can only be dialled from within the region, returns
@ -617,7 +637,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// the region was unknown, or the region 001 is passed in. For 001
// (representing non-geographical numbers), call
// GetExampleNumberForNonGeoEntity instead.
bool GetExampleNumber(const std::string& region_code,
bool GetExampleNumber(const string& region_code,
PhoneNumber* number) const;
// Gets an invalid number for the specified region. This is useful for
@ -629,14 +649,14 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
//
// Returns false when an unsupported region or the region 001 (Earth) is
// passed in.
bool GetInvalidExampleNumber(const std::string& region_code,
bool GetInvalidExampleNumber(const string& region_code,
PhoneNumber* number) const;
// Gets a valid number of the specified type for the specified region.
// Returns false if the region was unknown or 001, or if no example number of
// that type could be found. For 001 (representing non-geographical numbers),
// call GetExampleNumberForNonGeoEntity instead.
bool GetExampleNumberForType(const std::string& region_code,
bool GetExampleNumberForType(const string& region_code,
PhoneNumberType type,
PhoneNumber* number) const;
@ -691,15 +711,15 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// number (e.g.too few or too many digits) or if no default region was
// supplied and the number is not in international format (does not start with
// +).
ErrorType Parse(absl::string_view number_to_parse,
const std::string& default_region,
ErrorType Parse(const string& number_to_parse,
const string& default_region,
PhoneNumber* number) const;
// Parses a string and returns it in proto buffer format. This method differs
// from Parse() in that it always populates the raw_input field of the
// protocol buffer with number_to_parse as well as the country_code_source
// field.
ErrorType ParseAndKeepRawInput(absl::string_view number_to_parse,
const std::string& default_region,
ErrorType ParseAndKeepRawInput(const string& number_to_parse,
const string& default_region,
PhoneNumber* number) const;
// Takes two phone numbers and compares them for equality.
@ -723,8 +743,8 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// PhoneNumber secondNumber). No default region is known.
// Returns INVALID_NUMBER if either number cannot be parsed into a phone
// number.
MatchType IsNumberMatchWithTwoStrings(absl::string_view first_number,
absl::string_view second_number) const;
MatchType IsNumberMatchWithTwoStrings(const string& first_number,
const string& second_number) const;
// Takes two phone numbers and compares them for equality. This is a
// convenience wrapper for IsNumberMatch(PhoneNumber firstNumber,
@ -732,7 +752,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// Returns INVALID_NUMBER if second_number cannot be parsed into a phone
// number.
MatchType IsNumberMatchWithOneString(const PhoneNumber& first_number,
absl::string_view second_number) const;
const string& second_number) const;
// Overrides the default logging system. This takes ownership of the provided
// logger.
@ -743,7 +763,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// numbers in the specific region "as you type".
// The deletion of the returned instance is under the responsibility of the
// caller.
AsYouTypeFormatter* GetAsYouTypeFormatter(const std::string& region_code) const;
AsYouTypeFormatter* GetAsYouTypeFormatter(const string& region_code) const;
friend bool ConvertFromTelephoneNumberProto(
const TelephoneNumber& proto_to_convert,
@ -752,16 +772,16 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
TelephoneNumber* resulting_proto);
protected:
bool IsNumberMatchingDesc(const std::string& national_number,
bool IsNumberMatchingDesc(const string& national_number,
const PhoneNumberDesc& number_desc) const;
PhoneNumberUtil::PhoneNumberType GetNumberTypeHelper(
const std::string& national_number, const PhoneMetadata& metadata) const;
const string& national_number, const PhoneMetadata& metadata) const;
private:
scoped_ptr<Logger> logger_;
typedef std::pair<int, std::list<std::string>*> IntRegionsPair;
typedef std::pair<int, std::list<string>*> IntRegionsPair;
// The minimum and maximum length of the national significant number.
static const size_t kMinLengthForNsn = 2;
@ -806,11 +826,11 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
country_calling_code_to_region_code_map_;
// The set of regions that share country calling code 1.
scoped_ptr<absl::node_hash_set<std::string> > nanpa_regions_;
scoped_ptr<absl::node_hash_set<string> > nanpa_regions_;
static const int kNanpaCountryCode = 1;
// A mapping from a region code to a PhoneMetadata for that region.
scoped_ptr<absl::node_hash_map<std::string, PhoneMetadata> > region_to_metadata_map_;
scoped_ptr<absl::node_hash_map<string, PhoneMetadata> > region_to_metadata_map_;
// A mapping from a country calling code for a non-geographical entity to the
// PhoneMetadata for that country calling code. Examples of the country
@ -823,144 +843,154 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> {
// Returns a regular expression for the possible extensions that may be found
// in a number, for use when matching.
const std::string& GetExtnPatternsForMatching() const;
const string& GetExtnPatternsForMatching() const;
// Checks if a number matches the plus chars pattern.
bool StartsWithPlusCharsPattern(const std::string& number) const;
bool StartsWithPlusCharsPattern(const string& number) const;
void SetItalianLeadingZerosForPhoneNumber(const std::string& national_number,
PhoneNumber* phone_number) const;
void SetItalianLeadingZerosForPhoneNumber(
const string& national_number, PhoneNumber* phone_number) const;
// Checks whether a string contains only valid digits.
bool ContainsOnlyValidDigits(const std::string& s) const;
bool ContainsOnlyValidDigits(const string& s) const;
// Checks if a format is eligible to be used by the AsYouTypeFormatter. This
// method is here rather than in asyoutypeformatter.h since it depends on the
// valid punctuation declared by the phone number util.
bool IsFormatEligibleForAsYouTypeFormatter(const std::string& format) const;
bool IsFormatEligibleForAsYouTypeFormatter(const string& format) const;
// Helper function to check if the national prefix formatting rule has the
// first group only, i.e., does not start with the national prefix.
bool FormattingRuleHasFirstGroupOnly(
const std::string& national_prefix_formatting_rule) const;
const string& national_prefix_formatting_rule) const;
// Trims unwanted end characters from a phone number string.
void TrimUnwantedEndChars(std::string* number) const;
void TrimUnwantedEndChars(string* number) const;
// Helper function to check region code is not unknown or null.
bool IsValidRegionCode(const std::string& region_code) const;
bool IsValidRegionCode(const string& region_code) const;
// Helper function to check the country calling code is valid.
bool HasValidCountryCallingCode(int country_calling_code) const;
const i18n::phonenumbers::PhoneMetadata* GetMetadataForRegion(
const std::string& region_code) const;
const string& region_code) const;
const i18n::phonenumbers::PhoneMetadata* GetMetadataForNonGeographicalRegion(
int country_calling_code) const;
const i18n::phonenumbers::PhoneMetadata* GetMetadataForRegionOrCallingCode(
int country_calling_code,
const std::string& region_code) const;
const string& region_code) const;
// As per GetCountryCodeForRegion, but assumes the validity of the region_code
// has already been checked.
int GetCountryCodeForValidRegion(const std::string& region_code) const;
int GetCountryCodeForValidRegion(const string& region_code) const;
const NumberFormat* ChooseFormattingPatternForNumber(
const RepeatedPtrField<NumberFormat>& available_formats,
const std::string& national_number) const;
const string& national_number) const;
void FormatNsnUsingPatternWithCarrier(
const std::string& national_number,
const string& national_number,
const NumberFormat& formatting_pattern,
PhoneNumberUtil::PhoneNumberFormat number_format,
const std::string& carrier_code, std::string* formatted_number) const;
const string& carrier_code,
string* formatted_number) const;
void FormatNsnUsingPattern(const std::string& national_number,
const NumberFormat& formatting_pattern,
PhoneNumberUtil::PhoneNumberFormat number_format,
std::string* formatted_number) const;
void FormatNsnUsingPattern(
const string& national_number,
const NumberFormat& formatting_pattern,
PhoneNumberUtil::PhoneNumberFormat number_format,
string* formatted_number) const;
// Check if raw_input, which is assumed to be in the national format, has a
// national prefix. The national prefix is assumed to be in digits-only form.
bool RawInputContainsNationalPrefix(
const std::string& raw_input, const std::string& national_prefix,
const std::string& region_code) const;
const string& raw_input,
const string& national_prefix,
const string& region_code) const;
bool HasFormattingPatternForNumber(const PhoneNumber& number) const;
// Simple wrapper of FormatNsnWithCarrier for the common case of
// no carrier code.
void FormatNsn(const std::string& number, const PhoneMetadata& metadata,
void FormatNsn(const string& number,
const PhoneMetadata& metadata,
PhoneNumberFormat number_format,
std::string* formatted_number) const;
string* formatted_number) const;
void FormatNsnWithCarrier(const std::string& number,
void FormatNsnWithCarrier(const string& number,
const PhoneMetadata& metadata,
PhoneNumberFormat number_format,
const std::string& carrier_code,
std::string* formatted_number) const;
const string& carrier_code,
string* formatted_number) const;
void MaybeAppendFormattedExtension(const PhoneNumber& number,
const PhoneMetadata& metadata,
PhoneNumberFormat number_format,
std::string* extension) const;
void MaybeAppendFormattedExtension(
const PhoneNumber& number,
const PhoneMetadata& metadata,
PhoneNumberFormat number_format,
string* formatted_number) const;
void GetRegionCodeForNumberFromRegionList(
const PhoneNumber& number,
const std::list<std::string>& region_codes,
std::string* region_code) const;
const std::list<string>& region_codes,
string* region_code) const;
// Strips the IDD from the start of the number if present. Helper function
// used by MaybeStripInternationalPrefixAndNormalize.
bool ParsePrefixAsIdd(const RegExp& idd_pattern, std::string* number) const;
bool ParsePrefixAsIdd(const RegExp& idd_pattern, string* number) const;
void Normalize(std::string* number) const;
void Normalize(string* number) const;
PhoneNumber::CountryCodeSource MaybeStripInternationalPrefixAndNormalize(
const std::string& possible_idd_prefix, std::string* number) const;
const string& possible_idd_prefix,
string* number) const;
bool MaybeStripNationalPrefixAndCarrierCode(const PhoneMetadata& metadata,
std::string* number,
std::string* carrier_code) const;
bool MaybeStripNationalPrefixAndCarrierCode(
const PhoneMetadata& metadata,
string* number,
string* carrier_code) const;
void ExtractPossibleNumber(absl::string_view number,
std::string* extracted_number) const;
void ExtractPossibleNumber(const string& number,
string* extracted_number) const;
bool IsViablePhoneNumber(const std::string& number) const;
bool IsViablePhoneNumber(const string& number) const;
bool MaybeStripExtension(std::string* number, std::string* extension) const;
bool MaybeStripExtension(string* number, string* extension) const;
int ExtractCountryCode(std::string* national_number) const;
int ExtractCountryCode(string* national_number) const;
ErrorType MaybeExtractCountryCode(
const PhoneMetadata* default_region_metadata, bool keepRawInput,
std::string* national_number, PhoneNumber* phone_number) const;
bool CheckRegionForParsing(const std::string& number_to_parse,
const std::string& default_region) const;
ErrorType ParseHelper(absl::string_view number_to_parse,
const std::string& default_region,
bool keep_raw_input, bool check_region,
const PhoneMetadata* default_region_metadata,
bool keep_raw_input,
string* national_number,
PhoneNumber* phone_number) const;
bool CheckRegionForParsing(
const string& number_to_parse,
const string& default_region) const;
ErrorType ParseHelper(const string& number_to_parse,
const string& default_region,
bool keep_raw_input,
bool check_region,
PhoneNumber* phone_number) const;
absl::optional<absl::string_view> ExtractPhoneContext(
absl::string_view number_to_extract_from,
std::size_t index_of_phone_context) const;
absl::optional<string> ExtractPhoneContext(
const string& number_to_extract_from,
size_t index_of_phone_context) const;
bool IsPhoneContextValid(
absl::optional<absl::string_view> phone_context) const;
bool IsPhoneContextValid(absl::optional<string> phone_context) const;
ErrorType BuildNationalNumberForParsing(absl::string_view number_to_parse,
std::string* national_number) const;
ErrorType BuildNationalNumberForParsing(const string& number_to_parse,
string* national_number) const;
bool IsShorterThanPossibleNormalNumber(const PhoneMetadata* country_metadata,
const std::string& number) const;
const string& number) const;
};
} // namespace phonenumbers
} // namespace i18n
#endif // I18N_PHONENUMBERS_PHONENUMBERUTIL_H_
#endif // I18N_PHONENUMBERS_PHONENUMBERUTIL_H_

+ 3452
- 3445
cpp/src/phonenumbers/short_metadata.cc
File diff suppressed because it is too large
View File


+ 1
- 5
cpp/src/phonenumbers/stringutil.cc View File

@ -134,10 +134,6 @@ StringHolder::StringHolder(uint64 n)
: absl::AlphaNum(n)
{}
StringHolder::StringHolder(absl::string_view sv)
: absl::AlphaNum(sv)
{}
StringHolder::~StringHolder() {}
// StrCat
@ -297,4 +293,4 @@ void StrAppend(string* dest, const StringHolder& s1, const StringHolder& s2,
}
} // namespace phonenumbers
} // namespace i18n
} // namespace i18n

+ 4
- 5
cpp/src/phonenumbers/stringutil.h View File

@ -80,10 +80,9 @@ int GlobalReplaceSubstring(const string& substring, const string& replacement,
class StringHolder: public absl::AlphaNum {
public:
// Don't make the constructors explicit to make the StrCat usage convenient.
StringHolder(const string& s); // NOLINT(runtime/explicit)
StringHolder(const char* s); // NOLINT(runtime/explicit)
StringHolder(uint64_t n); // NOLINT(runtime/explicit)
StringHolder(absl::string_view sv); // NOLINT(runtime/explicit)
StringHolder(const string& s); // NOLINT(runtime/explicit)
StringHolder(const char* s); // NOLINT(runtime/explicit)
StringHolder(uint64_t n); // NOLINT(runtime/explicit)
~StringHolder();
const absl::string_view GetString() const {
@ -200,4 +199,4 @@ void StrAppend(string* dest, const StringHolder& s1, const StringHolder& s2,
} // namespace phonenumbers
} // namespace i18n
#endif // I18N_PHONENUMBERS_STRINGUTIL_H_
#endif // I18N_PHONENUMBERS_STRINGUTIL_H_

+ 64
- 0
cpp/test/phonenumbers/fuzz_asyoutypeformatter.cc View File

@ -0,0 +1,64 @@
/* Copyright 2025 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "phonenumbers/phonenumbermatcher.h"
#include <string>
#include <vector>
#include <limits>
#include <unicode/unistr.h>
#include "phonenumbers/base/basictypes.h"
#include "phonenumbers/base/memory/scoped_ptr.h"
#include "phonenumbers/base/memory/singleton.h"
#include "phonenumbers/default_logger.h"
#include "phonenumbers/phonenumber.h"
#include "phonenumbers/phonenumbermatch.h"
#include "phonenumbers/phonenumberutil.h"
#include "phonenumbers/stringutil.h"
#include "phonenumbers/asyoutypeformatter.h"
#include "phonenumbers/shortnumberinfo.h"
#include <fuzzer/FuzzedDataProvider.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// initial setup of all the structs we need
FuzzedDataProvider fuzzed_data(data, size);
i18n::phonenumbers::PhoneNumberUtil* phone_util =
i18n::phonenumbers::PhoneNumberUtil::GetInstance();
bool region_is_2_bytes = fuzzed_data.ConsumeBool();
std::string region = fuzzed_data.ConsumeBytesAsString(region_is_2_bytes ? 2 : 3);
std::unique_ptr<i18n::phonenumbers::AsYouTypeFormatter> formatter(
phone_util->GetAsYouTypeFormatter(region));
// setup the data passed to the target methods
const int iterations = fuzzed_data.ConsumeIntegralInRange(0, 32);
std::string result;
// Random amount of iterations
for (int i = 0; i < iterations; ++i) {
const char32_t next_char = fuzzed_data.ConsumeIntegral<char32_t>();
const bool remember = fuzzed_data.ConsumeBool();
// Randomly trigger the remember method
if (remember) {
formatter->InputDigitAndRememberPosition(next_char, &result);
} else {
formatter->InputDigit(next_char, &result);
}
// get the remembered position whether we remembered it or not
formatter->GetRememberedPosition();
}
return 0;
}

+ 85
- 0
cpp/test/phonenumbers/fuzz_matcher.cc View File

@ -0,0 +1,85 @@
/* Copyright 2025 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "phonenumbers/phonenumbermatcher.h"
#include <string>
#include <vector>
#include <limits>
#include <unicode/unistr.h>
#include "phonenumbers/base/basictypes.h"
#include "phonenumbers/base/memory/scoped_ptr.h"
#include "phonenumbers/base/memory/singleton.h"
#include "phonenumbers/default_logger.h"
#include "phonenumbers/phonenumber.h"
#include "phonenumbers/phonenumbermatch.h"
#include "phonenumbers/regexp_adapter_icu.h"
#include "phonenumbers/phonenumberutil.h"
#include "phonenumbers/stringutil.h"
#include "phonenumbers/asyoutypeformatter.h"
#include "phonenumbers/shortnumberinfo.h"
#include <fuzzer/FuzzedDataProvider.h>
// returns a leniency level based on the data we got from libfuzzer
i18n::phonenumbers::PhoneNumberMatcher::Leniency ConsumeLeniency(
FuzzedDataProvider& fuzzed_data) {
switch (fuzzed_data.ConsumeIntegralInRange(0, 3)) {
case 0:
return i18n::phonenumbers::PhoneNumberMatcher::Leniency::POSSIBLE;
case 1:
return i18n::phonenumbers::PhoneNumberMatcher::Leniency::VALID;
case 2:
return i18n::phonenumbers::PhoneNumberMatcher::Leniency::STRICT_GROUPING;
default:
return i18n::phonenumbers::PhoneNumberMatcher::Leniency::EXACT_GROUPING;
}
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Setup the data provider and util
FuzzedDataProvider fuzzed_data(data, size);
i18n::phonenumbers::PhoneNumberUtil* phone_util =
i18n::phonenumbers::PhoneNumberUtil::GetInstance();
// this should be enought to get at least 2 matches
std::string text = fuzzed_data.ConsumeBytesAsString(128);
// the region is either 2 or 3 characters long
bool region_is_2_bytes = fuzzed_data.ConsumeBool();
std::string region = fuzzed_data.ConsumeBytesAsString(region_is_2_bytes ? 2 : 3);
// setup fuzzed data for matchers
i18n::phonenumbers::PhoneNumberMatcher::Leniency leniency =
ConsumeLeniency(fuzzed_data);
int max_tries = fuzzed_data.ConsumeIntegralInRange(0, 500);
bool full_match = fuzzed_data.ConsumeBool();
std::string regexp_string = fuzzed_data.ConsumeRandomLengthString(32);
// initialize and fuzz the built-in matcher
i18n::phonenumbers::PhoneNumberMatcher matcher(*phone_util, text, region,
leniency, max_tries);
while (matcher.HasNext()) {
i18n::phonenumbers::PhoneNumberMatch match;
matcher.Next(&match);
}
// fuzz the matching with the icu adapter
std::string matched_string;
i18n::phonenumbers::ICURegExpFactory factory;
i18n::phonenumbers::RegExp* regexp = factory.CreateRegExp(regexp_string);
regexp->Match(text, full_match, &matched_string);
return 0;
}

+ 175
- 14
cpp/test/phonenumbers/fuzz_phone.cc View File

@ -15,7 +15,7 @@ limitations under the License.
#include "phonenumbers/phonenumbermatcher.h"
#include <string>
#include <vector>
#include <limits>
#include <unicode/unistr.h>
#include "phonenumbers/base/basictypes.h"
@ -23,26 +23,187 @@ limitations under the License.
#include "phonenumbers/base/memory/singleton.h"
#include "phonenumbers/default_logger.h"
#include "phonenumbers/phonenumber.h"
#include "phonenumbers/phonenumber.pb.h"
#include "phonenumbers/phonenumbermatch.h"
#include "phonenumbers/phonenumberutil.h"
#include "phonenumbers/stringutil.h"
#include "phonenumbers/asyoutypeformatter.h"
#include "phonenumbers/shortnumberinfo.h"
#include <fuzzer/FuzzedDataProvider.h>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
FuzzedDataProvider fuzzed_data(data, size);
using google::protobuf::RepeatedPtrField;
// consume PhoneNumberUtil::PhoneNumberType from libfuzzer data
i18n::phonenumbers::PhoneNumberUtil::PhoneNumberType ConsumePhoneNumberType(
FuzzedDataProvider& fuzzed_data) {
switch (fuzzed_data.ConsumeIntegralInRange(0, 11)) {
case 0:
return i18n::phonenumbers::PhoneNumberUtil::FIXED_LINE;
case 1:
return i18n::phonenumbers::PhoneNumberUtil::MOBILE;
case 2:
return i18n::phonenumbers::PhoneNumberUtil::FIXED_LINE_OR_MOBILE;
case 3:
return i18n::phonenumbers::PhoneNumberUtil::TOLL_FREE;
case 4:
return i18n::phonenumbers::PhoneNumberUtil::PREMIUM_RATE;
case 5:
return i18n::phonenumbers::PhoneNumberUtil::SHARED_COST;
case 6:
return i18n::phonenumbers::PhoneNumberUtil::VOIP;
case 7:
return i18n::phonenumbers::PhoneNumberUtil::PERSONAL_NUMBER;
case 8:
return i18n::phonenumbers::PhoneNumberUtil::PAGER;
case 9:
return i18n::phonenumbers::PhoneNumberUtil::UAN;
case 10:
return i18n::phonenumbers::PhoneNumberUtil::VOICEMAIL;
default:
return i18n::phonenumbers::PhoneNumberUtil::UNKNOWN;
}
}
// consume PhoneNumberUtil::PhoneNumberFormat from libfuzzer data
i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat ConsumePhoneNumberFormat(
FuzzedDataProvider& fuzzed_data) {
switch (fuzzed_data.ConsumeIntegralInRange(0, 3)) {
case 0:
return i18n::phonenumbers::PhoneNumberUtil::E164;
case 1:
return i18n::phonenumbers::PhoneNumberUtil::INTERNATIONAL;
case 2:
return i18n::phonenumbers::PhoneNumberUtil::NATIONAL;
default:
return i18n::phonenumbers::PhoneNumberUtil::RFC3966;
}
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// initialize the phone util
i18n::phonenumbers::PhoneNumberUtil* phone_util =
i18n::phonenumbers::PhoneNumberUtil::GetInstance();
FuzzedDataProvider fuzzed_data(data, size);
// initialize the first phone number, region and country calling code
i18n::phonenumbers::PhoneNumber phone_number;
bool region_is_2_bytes = fuzzed_data.ConsumeBool();
std::string region = fuzzed_data.ConsumeBytesAsString(region_is_2_bytes ? 2 : 3);
std::string number = fuzzed_data.ConsumeRandomLengthString(32);
int country_calling_code = fuzzed_data.ConsumeIntegral<int>();
// trigger either one of the public parse methods
if (fuzzed_data.ConsumeBool()) {
phone_util->ParseAndKeepRawInput(number, region, &phone_number);
} else {
phone_util->Parse(number, region, &phone_number);
}
// initialize the second phone number, this is used only for the
// isNumberMatch* methods
i18n::phonenumbers::PhoneNumber phone_number2;
std::string number2 = fuzzed_data.ConsumeRandomLengthString(32);
if (fuzzed_data.ConsumeBool()) {
phone_util->ParseAndKeepRawInput(number2, region, &phone_number2);
} else {
phone_util->Parse(number2, region, &phone_number2);
}
// randomly trigger the truncate method, this may affect state of the input
// for the method calls that follow it
if (fuzzed_data.ConsumeIntegralInRange(0, 10) == 5) {
phone_util->TruncateTooLongNumber(&phone_number);
}
// fuzz public methods
phone_util->IsAlphaNumber(number);
phone_util->IsPossibleNumber(phone_number);
phone_util->IsNumberMatch(phone_number, phone_number2);
phone_util->IsNumberMatchWithOneString(phone_number, number2);
phone_util->IsNumberMatchWithTwoStrings(number, number2);
phone_util->CanBeInternationallyDialled(phone_number);
phone_util->GetNumberType(phone_number);
phone_util->GetLengthOfGeographicalAreaCode(phone_number);
phone_util->GetLengthOfNationalDestinationCode(phone_number);
phone_util->IsNANPACountry(region);
phone_util->GetCountryCodeForRegion(region);
phone_util->IsPossibleNumberForString(number, region);
phone_util->IsNumberGeographical(phone_number);
i18n::phonenumbers::PhoneNumberUtil::PhoneNumberType number_type =
ConsumePhoneNumberType(fuzzed_data);
phone_util->IsNumberGeographical(number_type, country_calling_code);
phone_util->IsPossibleNumberForType(phone_number, number_type);
i18n::phonenumbers::PhoneNumber example_number;
phone_util->GetExampleNumberForType(region, number_type, &example_number);
i18n::phonenumbers::PhoneNumber example_number_2;
phone_util->GetExampleNumberForType(number_type, &example_number_2);
i18n::phonenumbers::PhoneNumber invalid_number;
phone_util->GetInvalidExampleNumber(region, &invalid_number);
i18n::phonenumbers::PhoneNumber non_geo_number;
phone_util->GetExampleNumberForNonGeoEntity(country_calling_code, &non_geo_number);
std::string output;
phone_util->GetCountryMobileToken(country_calling_code, &output);
output.clear();
phone_util->GetRegionCodeForNumber(phone_number, &output);
output.clear();
phone_util->GetNddPrefixForRegion(region, fuzzed_data.ConsumeBool(), &output);
output.clear();
// Fuzz the methods which affect the input string, but not the PhoneNumber object
std::string input = fuzzed_data.ConsumeRandomLengthString(32);
phone_util->ConvertAlphaCharactersInNumber(&input);
input.clear();
input = fuzzed_data.ConsumeRandomLengthString(32);
phone_util->NormalizeDigitsOnly(&input);
input.clear();
input = fuzzed_data.ConsumeRandomLengthString(32);
phone_util->NormalizeDiallableCharsOnly(&input);
input.clear();
// Fuzz the formatting methods
i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat format = ConsumePhoneNumberFormat(fuzzed_data);
std::string formatted;
phone_util->Format(phone_number, format, &formatted);
formatted.clear();
phone_util->FormatInOriginalFormat(phone_number, region, &formatted);
formatted.clear();
phone_util->FormatNumberForMobileDialing(phone_number, region,
fuzzed_data.ConsumeBool(), &formatted);
formatted.clear();
phone_util->FormatNationalNumberWithPreferredCarrierCode(phone_number, region, &formatted);
formatted.clear();
phone_util->FormatOutOfCountryKeepingAlphaChars(phone_number, region, &formatted);
formatted.clear();
std::string input = fuzzed_data.ConsumeRandomLengthString();
std::string input2 = fuzzed_data.ConsumeRandomLengthString();
std::string carrier = fuzzed_data.ConsumeRandomLengthString(8);
phone_util->FormatNationalNumberWithCarrierCode(phone_number, carrier, &formatted);
formatted.clear();
i18n::phonenumbers::PhoneNumberUtil *phone_util = i18n::phonenumbers::PhoneNumberUtil::GetInstance();
i18n::phonenumbers::PhoneNumber parsed;
// setup the parameters for FormatByPattern
i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat number_format = ConsumePhoneNumberFormat(fuzzed_data);
RepeatedPtrField<i18n::phonenumbers::NumberFormat> number_formats;
i18n::phonenumbers::NumberFormat* temp_number_format = number_formats.Add();
std::string pattern = fuzzed_data.ConsumeRandomLengthString(16);
std::string format_string = fuzzed_data.ConsumeRandomLengthString(16);
temp_number_format->set_pattern(pattern);
temp_number_format->set_format(format_string);
phone_util->Parse(input, input2, &parsed);
phone_util->IsValidNumber(parsed);
phone_util->GetCountryCodeForRegion(input);
// fuzz FormatByPattern
phone_util->FormatByPattern(phone_number, number_format, number_formats, &formatted);
formatted.clear();
return 0;
return 0;
}

+ 79
- 0
cpp/test/phonenumbers/fuzz_shortnumberinfo.cc View File

@ -0,0 +1,79 @@
/* Copyright 2025 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "phonenumbers/phonenumbermatcher.h"
#include <string>
#include <vector>
#include <limits>
#include <unicode/unistr.h>
#include "phonenumbers/base/basictypes.h"
#include "phonenumbers/base/memory/scoped_ptr.h"
#include "phonenumbers/base/memory/singleton.h"
#include "phonenumbers/default_logger.h"
#include "phonenumbers/phonenumber.h"
#include "phonenumbers/phonenumbermatch.h"
#include "phonenumbers/phonenumberutil.h"
#include "phonenumbers/stringutil.h"
#include "phonenumbers/asyoutypeformatter.h"
#include "phonenumbers/shortnumberinfo.h"
#include <fuzzer/FuzzedDataProvider.h>
// returns a short number cost based on the data we got from libfuzzer
i18n::phonenumbers::ShortNumberInfo::ShortNumberCost ConsumeShortNumberCost(
FuzzedDataProvider& fuzzed_data) {
switch (fuzzed_data.ConsumeIntegralInRange(0, 4)) {
case 0: return i18n::phonenumbers::ShortNumberInfo::TOLL_FREE;
case 1: return i18n::phonenumbers::ShortNumberInfo::STANDARD_RATE;
case 2: return i18n::phonenumbers::ShortNumberInfo::PREMIUM_RATE;
default: return i18n::phonenumbers::ShortNumberInfo::UNKNOWN_COST;
}
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// setup the data provider and util
FuzzedDataProvider fuzzed_data(data, size);
i18n::phonenumbers::PhoneNumberUtil* phone_util =
i18n::phonenumbers::PhoneNumberUtil::GetInstance();
// setup all the data we need to pass to the target methods
i18n::phonenumbers::PhoneNumber phone_number;
std::string number = fuzzed_data.ConsumeRandomLengthString(32);
bool region_is_2_bytes = fuzzed_data.ConsumeBool();
std::string region = fuzzed_data.ConsumeBytesAsString(region_is_2_bytes ? 2 : 3);
if (fuzzed_data.ConsumeBool()) {
phone_util->ParseAndKeepRawInput(number, region, &phone_number);
} else {
phone_util->Parse(number, region, &phone_number);
}
// fuzz the public methods
i18n::phonenumbers::ShortNumberInfo short_info;
short_info.IsPossibleShortNumberForRegion(phone_number, region);
short_info.IsPossibleShortNumber(phone_number);
short_info.IsValidShortNumber(phone_number);
short_info.GetExpectedCostForRegion(phone_number, region);
short_info.GetExpectedCost(phone_number);
short_info.GetExampleShortNumber(region);
i18n::phonenumbers::ShortNumberInfo::ShortNumberCost cost =
ConsumeShortNumberCost(fuzzed_data);
short_info.GetExampleShortNumberForCost(region, cost);
short_info.ConnectsToEmergencyNumber(number, region);
short_info.IsEmergencyNumber(number, region);
short_info.IsCarrierSpecific(phone_number);
short_info.IsCarrierSpecificForRegion(phone_number, region);
short_info.IsSmsServiceForRegion(phone_number, region);
return 0;
}

+ 10
- 0
cpp/test/phonenumbers/phonenumberutil_test.cc View File

@ -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();


+ 14
- 12
java/carrier/pom.xml View File

@ -1,16 +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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>carrier</artifactId>
<version>1.234-SNAPSHOT</version>
<version>2.4-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.50-SNAPSHOT</version>
<version>9.0.4-SNAPSHOT</version>
</parent>
<build>
@ -24,8 +23,10 @@
</resources>
<testResources>
<testResource>
<directory>test/com/google/i18n/phonenumbers/carrier/testing_data</directory>
<targetPath>com/google/i18n/phonenumbers/carrier/testing_data</targetPath>
<directory>test/com/google/i18n/phonenumbers/carrier/testing_data
</directory>
<targetPath>com/google/i18n/phonenumbers/carrier/testing_data
</targetPath>
</testResource>
</testResources>
<plugins>
@ -35,24 +36,25 @@
<version>5.1.9</version>
<configuration>
<instructions>
<Fragment-Host>com.googlecode.libphonenumber</Fragment-Host>
<Fragment-Host>com.googlecode.libphonenumber</Fragment-Host>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestFile>
${project.build.outputDirectory}/META-INF/MANIFEST.MF
</manifestFile>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
@ -79,12 +81,12 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.50-SNAPSHOT</version>
<version>9.0.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>prefixmapper</artifactId>
<version>2.244-SNAPSHOT</version>
<version>3.4-SNAPSHOT</version>
</dependency>
</dependencies>


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/1671_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/212_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/221_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/223_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/228_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/229_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/252_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/255_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/256_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/260_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/262_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/268_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/27_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/33_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/34_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/351_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/36_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/371_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/385_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/389_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/41_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/43_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/45_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/48_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/503_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/508_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/51_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/58_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/590_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/592_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/594_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/596_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/597_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/65_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/674_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/680_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/81_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/852_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/852_zh View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/855_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/90_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/92_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/963_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/972_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/976_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/992_en View File


BIN
java/carrier/src/com/google/i18n/phonenumbers/carrier/data/995_en View File


+ 7
- 7
java/demo/pom.xml View File

@ -3,21 +3,21 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>demo</artifactId>
<version>8.13.50-SNAPSHOT</version>
<version>9.0.4-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.50-SNAPSHOT</version>
<version>9.0.4-SNAPSHOT</version>
</parent>
<properties>
<app.deploy.project>libphonenumber-hrd</app.deploy.project>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<archiveClasses>true</archiveClasses>
<soy.root>${project.basedir}/src/main/resources/com/google/phonenumbers/demo</soy.root>
@ -68,17 +68,17 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.50-SNAPSHOT</version>
<version>9.0.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>geocoder</artifactId>
<version>2.244-SNAPSHOT</version>
<version>3.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>carrier</artifactId>
<version>1.234-SNAPSHOT</version>
<version>2.4-SNAPSHOT</version>
</dependency>
</dependencies>


+ 19
- 21
java/demo/src/main/resources/com/google/phonenumbers/demo/result.soy View File

@ -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>


+ 1
- 1
java/demo/src/main/webapp/WEB-INF/appengine-web.xml View File

@ -2,7 +2,7 @@
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>libphonenumber-hrd</application>
<version>1</version>
<runtime>java11</runtime>
<runtime>java17</runtime>
<threadsafe>true</threadsafe>
<!-- Configure java.util.logging -->


+ 18
- 14
java/geocoder/pom.xml View File

@ -1,16 +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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>geocoder</artifactId>
<version>2.244-SNAPSHOT</version>
<version>3.4-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.50-SNAPSHOT</version>
<version>9.0.4-SNAPSHOT</version>
</parent>
<build>
@ -28,12 +27,16 @@
</resources>
<testResources>
<testResource>
<directory>test/com/google/i18n/phonenumbers/geocoding/testing_data</directory>
<targetPath>com/google/i18n/phonenumbers/geocoding/testing_data</targetPath>
<directory>test/com/google/i18n/phonenumbers/geocoding/testing_data
</directory>
<targetPath>com/google/i18n/phonenumbers/geocoding/testing_data
</targetPath>
</testResource>
<testResource>
<directory>test/com/google/i18n/phonenumbers/timezones/testing_data</directory>
<targetPath>com/google/i18n/phonenumbers/timezones/testing_data</targetPath>
<directory>test/com/google/i18n/phonenumbers/timezones/testing_data
</directory>
<targetPath>com/google/i18n/phonenumbers/timezones/testing_data
</targetPath>
</testResource>
</testResources>
<plugins>
@ -43,24 +46,25 @@
<version>5.1.9</version>
<configuration>
<instructions>
<Fragment-Host>com.googlecode.libphonenumber</Fragment-Host>
<Fragment-Host>com.googlecode.libphonenumber</Fragment-Host>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestFile>
${project.build.outputDirectory}/META-INF/MANIFEST.MF
</manifestFile>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
@ -87,12 +91,12 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.50-SNAPSHOT</version>
<version>9.0.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>prefixmapper</artifactId>
<version>2.244-SNAPSHOT</version>
<version>3.4-SNAPSHOT</version>
</dependency>
</dependencies>


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1274_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1327_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1345_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1821_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1942_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/372_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/52_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_en View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_zh View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/config View File


BIN
java/geocoder/src/com/google/i18n/phonenumbers/timezones/data/map_data View File


+ 19
- 11
java/internal/prefixmapper/pom.xml View File

@ -1,16 +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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>prefixmapper</artifactId>
<version>2.244-SNAPSHOT</version>
<version>3.4-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.50-SNAPSHOT</version>
<version>9.0.4-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
@ -19,8 +18,11 @@
<testSourceDirectory>test</testSourceDirectory>
<testResources>
<testResource>
<directory>../../geocoder/test/com/google/i18n/phonenumbers/geocoding/testing_data</directory>
<targetPath>com/google/i18n/phonenumbers/geocoding/testing_data</targetPath>
<directory>
../../geocoder/test/com/google/i18n/phonenumbers/geocoding/testing_data
</directory>
<targetPath>com/google/i18n/phonenumbers/geocoding/testing_data
</targetPath>
</testResource>
</testResources>
<plugins>
@ -30,24 +32,30 @@
<version>5.1.9</version>
<configuration>
<instructions>
<Fragment-Host>com.googlecode.libphonenumber</Fragment-Host>
<Fragment-Host>com.googlecode.libphonenumber</Fragment-Host>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestFile>
${project.build.outputDirectory}/META-INF/MANIFEST.MF
</manifestFile>
<manifestEntries>
<Automatic-Module-Name>
com.google.i18n.phonenumbers.prefixmapper
</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
@ -75,7 +83,7 @@
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.50-SNAPSHOT</version>
<version>9.0.4-SNAPSHOT</version>
</dependency>
</dependencies>


+ 19
- 7
java/libphonenumber/pom.xml View File

@ -1,16 +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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.13.50-SNAPSHOT</version>
<version>9.0.4-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.50-SNAPSHOT</version>
<version>9.0.4-SNAPSHOT</version>
</parent>
<build>
@ -35,20 +34,26 @@
<version>5.1.9</version>
<configuration>
<instructions>
<Eclipse-ExtensibleAPI>true</Eclipse-ExtensibleAPI>
<Eclipse-ExtensibleAPI>true</Eclipse-ExtensibleAPI>
<Export-Package>com.google.i18n.phonenumbers</Export-Package>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestFile>
${project.build.outputDirectory}/META-INF/MANIFEST.MF
</manifestFile>
<manifestEntries>
<Automatic-Module-Name>
com.google.i18n.phonenumbers.libphonenumber
</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</execution>
@ -61,7 +66,14 @@
<configuration>
<classifier>no-metadata</classifier>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestFile>
${project.build.outputDirectory}/META-INF/MANIFEST.MF
</manifestFile>
<manifestEntries>
<Automatic-Module-Name>
com.google.i18n.phonenumbers.libphonenumber
</Automatic-Module-Name>
</manifestEntries>
</archive>
<excludes>
<exclude>com/google/i18n/phonenumbers/data/*</exclude>


+ 18
- 2
java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java View File

@ -1878,8 +1878,11 @@ public class PhoneNumberUtil {
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);
@ -2705,6 +2708,13 @@ public class PhoneNumberUtil {
* 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
*/
@ -2734,6 +2744,12 @@ public class PhoneNumberUtil {
* 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


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberAlternateFormatsProto_385 View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberAlternateFormatsProto_43 View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_870 View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AR View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AT View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BE View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BJ View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BL View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CA View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CZ View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DE View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_DK View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_EH View File


BIN
java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FI View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save