Skip to content

Commit

Permalink
Upstream changes from Google for v8.12.29 (#456)
Browse files Browse the repository at this point in the history
Code changes:
 - Updated As-You-Type-Formatter to exclude patterns where some digits
   would be dropped in the output. This also fixes the bug where an
extra country code is added in some cases to the user's output.
b/183053929

Metadata changes:
 - Updated phone metadata for region code(s): BE, GE, IR, MO, MX, QA, SN
 - Updated geocoding data for country calling code(s): 52 (en)
 - Updated carrier data for country calling code(s):
   32 (en), 221 (en), 995 (en)
 - Updated / refreshed time zone meta data.
  • Loading branch information
giggsey authored Aug 6, 2021
1 parent f503d56 commit 407bbbb
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 32 deletions.
2 changes: 1 addition & 1 deletion METADATA-VERSION.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# It can be a commit, branch or tag of the https://github.com/google/libphonenumber project
#
# For more information, look at the phing tasks in build.xml
v8.12.28
v8.12.29
9 changes: 6 additions & 3 deletions phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) {
exit(1);
}

putenv('SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1');
putenv("SYMFONY_DEPRECATIONS_HELPER=disabled=1");

if (!getenv('SYMFONY_PHPUNIT_VERSION')) {
if (\PHP_VERSION_ID > 70400) {
if (\PHP_VERSION_ID > 80000) {
putenv('SYMFONY_PHPUNIT_VERSION=9.5');
} elseif (\PHP_VERSION_ID > 70400) {
putenv('SYMFONY_PHPUNIT_VERSION=7.5');
} elseif (\PHP_VERSION_ID > 80000) {
putenv('SYMFONY_PHPUNIT_VERSION=9.4');
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/AsYouTypeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ class AsYouTypeFormatter
* to be used by the AYTF. It is eligible when the format element under numberFormat contains
* groups of the dollar sign followed by a single digit, separated by valid phone number punctuation.
* This prevents invalid punctuation (such as the star sign in Israeli star numbers) getting
* into the output of the AYTF.
* into the output of the AYTF. We require that the first group is present in the output pattern to ensure
* no data is lost while formatting; when we format as you type, this should always be the case.
* @var string
*/
private static $eligibleFormatPattern;
Expand Down Expand Up @@ -186,7 +187,8 @@ private static function init()
self::$emptyMetadata->setInternationalPrefix('NA');

self::$eligibleFormatPattern = '[' . PhoneNumberUtil::VALID_PUNCTUATION . ']*'
. "(\\$\\d" . '[' . PhoneNumberUtil::VALID_PUNCTUATION . ']*)+';
. "\\$1" . "[" . PhoneNumberUtil::VALID_PUNCTUATION . "]*(\\$\\d"
. "[" . PhoneNumberUtil::VALID_PUNCTUATION . "]*)*";
}
}

Expand Down
1 change: 1 addition & 0 deletions src/PhoneNumberMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ protected static function loadAlternateFormatsMetadataFromFile($countryCallingCo
* @link http://php.net/manual/en/iterator.current.php
* @return PhoneNumberMatch|null
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->lastMatch;
Expand Down
4 changes: 1 addition & 3 deletions src/carrier/data/en/221.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
return array (
22170 => 'Expresso',
22172 => 'HAYO',
221754 => 'Promobile',
221755 => 'Promobile',
221756 => 'Promobile',
22175 => 'Promobile',
221757 => 'Origines',
22176 => 'Tigo',
22177 => 'Orange',
Expand Down
1 change: 1 addition & 0 deletions src/carrier/data/en/32.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
324687 => 'Premium Routing GmbH',
324688 => 'Premium Routing GmbH',
324689 => 'Febo Telecom',
32469 => 'Telenet',
3247 => 'Proximus',
324805 => 'Voyacom SPRL',
324807 => 'MessageBird BV',
Expand Down
1 change: 1 addition & 0 deletions src/carrier/data/en/995.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
9955757 => 'MagtiCom',
995577 => 'Geocell',
995579 => 'Veon',
995580 => 'Silknet',
995585 => 'MagtiCom',
9955885 => 'Silknet',
9955888 => 'Geocell',
Expand Down
4 changes: 2 additions & 2 deletions src/data/PhoneNumberMetadata_BE.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
),
'premiumRate' =>
array (
'NationalNumberPattern' => '(?:70(?:2[0-57]|3[0457]|44|69|7[0579])|90(?:0[0-35-8]|1[36]|2[0-3568]|3[0135689]|4[2-68]|5[1-68]|6[0-378]|7[23568]|9[34679]))\\d{4}',
'NationalNumberPattern' => '(?:70(?:2[0-57]|3[04-7]|44|69|7[0579])|90(?:0[0-8]|1[36]|2[0-3568]|3[013-689]|[47][2-68]|5[1-68]|6[0-378]|9[34679]))\\d{4}',
'ExampleNumber' => '90012345',
'PossibleLength' =>
array (
Expand Down Expand Up @@ -116,7 +116,7 @@
),
'uan' =>
array (
'NationalNumberPattern' => '78(?:0[57]|1[0458]|2[25]|3[15-8]|48|[56]0|7[078])\\d{4}',
'NationalNumberPattern' => '78(?:0[57]|1[0458]|2[25]|3[15-8]|48|[56]0|7[078]|9\\d)\\d{4}',
'ExampleNumber' => '78102345',
'PossibleLength' =>
array (
Expand Down
2 changes: 1 addition & 1 deletion src/data/PhoneNumberMetadata_GE.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
),
'mobile' =>
array (
'NationalNumberPattern' => '5(?:0555[5-9]|757(?:7[7-9]|8[01]))\\d{3}|5(?:0070|[25]222|3333)[0-4]\\d{3}|5(?:00(?:0\\d|50)|111\\d|(?:52|75)00|8(?:58[89]|8(?:55|88)))\\d{4}|(?:5(?:[14]4|5[0157-9]|68|7[0147-9]|9[1-35-9])|790)\\d{6}',
'NationalNumberPattern' => '5(?:0555[5-9]|757(?:7[7-9]|8[01]))\\d{3}|5(?:0070|[25]222|3333)[0-4]\\d{3}|5(?:00(?:0\\d|50)|111\\d|(?:52|75)00|8(?:0(?:[01]\\d|2[0-4])|58[89]|8(?:55|88)))\\d{4}|(?:5(?:[14]4|5[0157-9]|68|7[0147-9]|9[1-35-9])|790)\\d{6}',
'ExampleNumber' => '555123456',
'PossibleLength' =>
array (
Expand Down
6 changes: 2 additions & 4 deletions src/data/PhoneNumberMetadata_IR.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
),
'mobile' =>
array (
'NationalNumberPattern' => '9(?:(?:0(?:[0-35]\\d|4[4-6])|(?:[13]\\d|2[0-3])\\d)\\d|9(?:(?:[0-2]\\d|3[01]|4[0145])\\d|5[15]0|8(?:1\\d|88)|9(?:0[013]|[19]\\d|21|77|8[7-9])))\\d{5}',
'NationalNumberPattern' => '9(?:(?:0(?:[0-35]\\d|4[4-6])|(?:[13]\\d|2[0-3])\\d)\\d|9(?:(?:[0-3]\\d|4[0145])\\d|5[15]0|8(?:1\\d|88)|9(?:0[013]|[19]\\d|21|77|8[7-9])))\\d{5}',
'ExampleNumber' => '9123456789',
'PossibleLength' =>
array (
Expand Down Expand Up @@ -99,11 +99,9 @@
),
'voip' =>
array (
'NationalNumberPattern' => '993[2-9]\\d{6}',
'ExampleNumber' => '9932123456',
'PossibleLength' =>
array (
0 => 10,
0 => -1,
),
'PossibleLengthLocalOnly' =>
array (
Expand Down
4 changes: 2 additions & 2 deletions src/data/PhoneNumberMetadata_MO.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
return array (
'generalDesc' =>
array (
'NationalNumberPattern' => '08005\\d\\d|(?:28|[68]\\d)\\d{6}',
'NationalNumberPattern' => '0800\\d{3}|(?:28|[68]\\d)\\d{6}',
'PossibleLength' =>
array (
0 => 7,
Expand Down Expand Up @@ -50,7 +50,7 @@
),
'tollFree' =>
array (
'NationalNumberPattern' => '08005\\d\\d',
'NationalNumberPattern' => '0800\\d{3}',
'ExampleNumber' => '0800501',
'PossibleLength' =>
array (
Expand Down
6 changes: 3 additions & 3 deletions src/data/PhoneNumberMetadata_MX.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
return array (
'generalDesc' =>
array (
'NationalNumberPattern' => '199[1-9]\\d{7}|(?:1(?:[01467]\\d|[235][1-9]|8[1-79]|9[1-8])|[2-9]\\d)\\d{8}',
'NationalNumberPattern' => '1(?:65[0-689]|99[1-9])\\d{7}|(?:1(?:[0147]\\d|[235][1-9]|6[0-46-9]|8[1-79]|9[1-8])|[2-9]\\d)\\d{8}',
'PossibleLength' =>
array (
0 => 10,
Expand All @@ -28,7 +28,7 @@
),
'fixedLine' =>
array (
'NationalNumberPattern' => '(?:2(?:0[01]|2[1-9]|3[1-35-8]|4[13-9]|7[1-689]|8[1-578]|9[467])|3(?:1[1-79]|[2458][1-9]|3\\d|7[1-8]|9[1-5])|4(?:1[1-57-9]|[24-7][1-9]|3[1-8]|8[1-35-9]|9[2-689])|5(?:[56]\\d|88|9[1-79])|6(?:1[2-68]|[2-4][1-9]|5[1-3689]|6[1-57-9]|7[1-7]|8[67]|9[4-8])|7(?:[1-467][1-9]|5[13-9]|8[1-69]|9[17])|8(?:1\\d|2[13-689]|3[1-6]|4[124-6]|6[1246-9]|7[1-378]|9[12479])|9(?:1[346-9]|2[1-4]|3[2-46-8]|5[1348]|6[1-9]|7[12]|8[1-8]|9\\d))\\d{7}',
'NationalNumberPattern' => '6571\\d{6}|(?:2(?:0[01]|2[1-9]|3[1-35-8]|4[13-9]|7[1-689]|8[1-578]|9[467])|3(?:1[1-79]|[2458][1-9]|3\\d|7[1-8]|9[1-5])|4(?:1[1-57-9]|[24-7][1-9]|3[1-8]|8[1-35-9]|9[2-689])|5(?:[56]\\d|88|9[1-79])|6(?:1[2-68]|[2-4][1-9]|5[1-3689]|6[1-57-9]|7[1-7]|8[67]|9[4-8])|7(?:[1-467][1-9]|5[13-9]|8[1-69]|9[17])|8(?:1\\d|2[13-689]|3[1-6]|4[124-6]|6[1246-9]|7[1-378]|9[12479])|9(?:1[346-9]|2[1-4]|3[2-46-8]|5[1348]|6[1-9]|7[12]|8[1-8]|9\\d))\\d{7}',
'ExampleNumber' => '2001234567',
'PossibleLength' =>
array (
Expand All @@ -42,7 +42,7 @@
),
'mobile' =>
array (
'NationalNumberPattern' => '(?:1(?:2(?:2[1-9]|3[1-35-8]|4[13-9]|7[1-689]|8[1-578]|9[467])|3(?:1[1-79]|[2458][1-9]|3\\d|7[1-8]|9[1-5])|4(?:1[1-57-9]|[24-7][1-9]|3[1-8]|8[1-35-9]|9[2-689])|5(?:[56]\\d|88|9[1-79])|6(?:1[2-68]|[2-4][1-9]|5[1-3689]|6[1-57-9]|7[1-7]|8[67]|9[4-8])|7(?:[1-467][1-9]|5[13-9]|8[1-69]|9[17])|8(?:1\\d|2[13-689]|3[1-6]|4[124-6]|6[1246-9]|7[1-378]|9[12479])|9(?:1[346-9]|2[1-4]|3[2-46-8]|5[1348]|[69][1-9]|7[12]|8[1-8]))|2(?:2[1-9]|3[1-35-8]|4[13-9]|7[1-689]|8[1-578]|9[467])|3(?:1[1-79]|[2458][1-9]|3\\d|7[1-8]|9[1-5])|4(?:1[1-57-9]|[24-7][1-9]|3[1-8]|8[1-35-9]|9[2-689])|5(?:[56]\\d|88|9[1-79])|6(?:1[2-68]|[2-4][1-9]|5[1-3689]|6[1-57-9]|7[1-7]|8[67]|9[4-8])|7(?:[1-467][1-9]|5[13-9]|8[1-69]|9[17])|8(?:1\\d|2[13-689]|3[1-6]|4[124-6]|6[1246-9]|7[1-378]|9[12479])|9(?:1[346-9]|2[1-4]|3[2-46-8]|5[1348]|6[1-9]|7[12]|8[1-8]|9\\d))\\d{7}',
'NationalNumberPattern' => '6571\\d{6}|(?:1(?:2(?:2[1-9]|3[1-35-8]|4[13-9]|7[1-689]|8[1-578]|9[467])|3(?:1[1-79]|[2458][1-9]|3\\d|7[1-8]|9[1-5])|4(?:1[1-57-9]|[24-7][1-9]|3[1-8]|8[1-35-9]|9[2-689])|5(?:[56]\\d|88|9[1-79])|6(?:1[2-68]|[2-4][1-9]|5[1-3689]|6[1-57-9]|7[1-7]|8[67]|9[4-8])|7(?:[1-467][1-9]|5[13-9]|8[1-69]|9[17])|8(?:1\\d|2[13-689]|3[1-6]|4[124-6]|6[1246-9]|7[1-378]|9[12479])|9(?:1[346-9]|2[1-4]|3[2-46-8]|5[1348]|[69][1-9]|7[12]|8[1-8]))|2(?:2[1-9]|3[1-35-8]|4[13-9]|7[1-689]|8[1-578]|9[467])|3(?:1[1-79]|[2458][1-9]|3\\d|7[1-8]|9[1-5])|4(?:1[1-57-9]|[24-7][1-9]|3[1-8]|8[1-35-9]|9[2-689])|5(?:[56]\\d|88|9[1-79])|6(?:1[2-68]|[2-4][1-9]|5[1-3689]|6[1-57-9]|7[1-7]|8[67]|9[4-8])|7(?:[1-467][1-9]|5[13-9]|8[1-69]|9[17])|8(?:1\\d|2[13-689]|3[1-6]|4[124-6]|6[1246-9]|7[1-378]|9[12479])|9(?:1[346-9]|2[1-4]|3[2-46-8]|5[1348]|6[1-9]|7[12]|8[1-8]|9\\d))\\d{7}',
'ExampleNumber' => '12221234567',
'PossibleLength' =>
array (
Expand Down
6 changes: 4 additions & 2 deletions src/data/PhoneNumberMetadata_QA.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
return array (
'generalDesc' =>
array (
'NationalNumberPattern' => '[2-7]\\d{7}|(?:2\\d\\d|800)\\d{4}',
'NationalNumberPattern' => '[2-7]\\d{7}|800\\d{4}(?:\\d{2})?|2\\d{6}',
'PossibleLength' =>
array (
0 => 7,
1 => 8,
2 => 9,
),
'PossibleLengthLocalOnly' =>
array (
Expand Down Expand Up @@ -50,11 +51,12 @@
),
'tollFree' =>
array (
'NationalNumberPattern' => '800\\d{4}',
'NationalNumberPattern' => '800\\d{4}(?:\\d{2})?',
'ExampleNumber' => '8001234',
'PossibleLength' =>
array (
0 => 7,
1 => 9,
),
'PossibleLengthLocalOnly' =>
array (
Expand Down
6 changes: 3 additions & 3 deletions src/data/PhoneNumberMetadata_SN.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
return array (
'generalDesc' =>
array (
'NationalNumberPattern' => '(?:[378]\\d{4}|93330)\\d{4}',
'NationalNumberPattern' => '(?:[378]\\d|93)\\d{7}',
'PossibleLength' =>
array (
0 => 9,
Expand All @@ -36,7 +36,7 @@
),
'mobile' =>
array (
'NationalNumberPattern' => '7(?:[06-8]\\d|21|5[4-7]|90)\\d{6}',
'NationalNumberPattern' => '75(?:01|[38]3)\\d{5}|7(?:[06-8]\\d|21|5[4-7]|90)\\d{6}',
'ExampleNumber' => '701234567',
'PossibleLength' =>
array (
Expand Down Expand Up @@ -90,7 +90,7 @@
),
'voip' =>
array (
'NationalNumberPattern' => '93330\\d{4}|3(?:392|9[01]\\d)\\d{5}',
'NationalNumberPattern' => '(?:3(?:392|9[01]\\d)\\d|93(?:3[13]0|929))\\d{4}',
'ExampleNumber' => '933301234',
'PossibleLength' =>
array (
Expand Down
1 change: 1 addition & 0 deletions src/geocoding/data/en/52.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
52652 => 'Chihuahua',
52653 => 'Luis B. Sanchez/San Luis Rio Colorado, SON',
52656 => 'Chihuahua',
52657 => 'Chihuahua',
52658 => 'Baja California',
52659 => 'Chihuahua',
52661 => 'Primo Tapia/Rosarito, BCN',
Expand Down
1 change: 1 addition & 0 deletions src/timezone/data/map_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -2305,6 +2305,7 @@
52652 => 'America/Mazatlan',
52653 => 'America/Mazatlan',
52656 => 'America/Hermosillo',
52657 => 'America/Mazatlan',
52658 => 'America/Tijuana',
52659 => 'America/Mazatlan',
52661 => 'America/Tijuana',
Expand Down
14 changes: 14 additions & 0 deletions tests/core/AsYouTypeFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,20 @@ public function testAYTF_MX()
$this->assertEquals('+52 800 123 456', $formatter->inputDigit('6'));
$this->assertEquals('+52 800 123 4567', $formatter->inputDigit('7'));

// +529011234567, proactively ensuring that no formatting is applied, where a format is chosen
// that would otherwise have led to some digits being dropped.
$formatter->clear();
$this->assertEquals("9", $formatter->inputDigit('9'));
$this->assertEquals("90", $formatter->inputDigit('0'));
$this->assertEquals("901", $formatter->inputDigit('1'));
$this->assertEquals("9011", $formatter->inputDigit('1'));
$this->assertEquals("90112", $formatter->inputDigit('2'));
$this->assertEquals("901123", $formatter->inputDigit('3'));
$this->assertEquals("9011234", $formatter->inputDigit('4'));
$this->assertEquals("90112345", $formatter->inputDigit('5'));
$this->assertEquals("901123456", $formatter->inputDigit('6'));
$this->assertEquals("9011234567", $formatter->inputDigit('7'));

// +52 55 1234 5678
$formatter->clear();
$this->assertEquals('+', $formatter->inputDigit('+'));
Expand Down
33 changes: 27 additions & 6 deletions tests/core/data/PhoneNumberMetadataForTesting_MX.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@
'nationalPrefixOptionalWhenFormatting' => true,
),
1 =>
array (
'pattern' => '(\\d{3})(\\d{2})(\\d{5})',
'format' => '$2 $3',
'leadingDigitsPatterns' =>
array (
0 => '901',
),
'nationalPrefixFormattingRule' => '01 $1',
'domesticCarrierCodeFormattingRule' => '',
'nationalPrefixOptionalWhenFormatting' => true,
),
2 =>
array (
'pattern' => '(\\d{2})(\\d{4})(\\d{4})',
'format' => '$1 $2 $3',
Expand All @@ -177,7 +189,7 @@
'domesticCarrierCodeFormattingRule' => '',
'nationalPrefixOptionalWhenFormatting' => true,
),
2 =>
3 =>
array (
'pattern' => '(\\d{3})(\\d{3})(\\d{4})',
'format' => '$1 $2 $3',
Expand All @@ -189,7 +201,7 @@
'domesticCarrierCodeFormattingRule' => '',
'nationalPrefixOptionalWhenFormatting' => true,
),
3 =>
4 =>
array (
'pattern' => '(\\d)(\\d{2})(\\d{4})(\\d{4})',
'format' => '045 $2 $3 $4',
Expand All @@ -201,7 +213,7 @@
'domesticCarrierCodeFormattingRule' => '',
'nationalPrefixOptionalWhenFormatting' => true,
),
4 =>
5 =>
array (
'pattern' => '(\\d)(\\d{3})(\\d{3})(\\d{4})',
'format' => '045 $2 $3 $4',
Expand Down Expand Up @@ -229,6 +241,15 @@
'nationalPrefixOptionalWhenFormatting' => true,
),
1 =>
array (
'pattern' => '(\\d{3})(\\d{2})(\\d{5})',
'format' => '$2 $3',
'leadingDigitsPatterns' =>
array (
0 => '901',
),
),
2 =>
array (
'pattern' => '(\\d{2})(\\d{4})(\\d{4})',
'format' => '$1 $2 $3',
Expand All @@ -240,7 +261,7 @@
'domesticCarrierCodeFormattingRule' => '',
'nationalPrefixOptionalWhenFormatting' => true,
),
2 =>
3 =>
array (
'pattern' => '(\\d{3})(\\d{3})(\\d{4})',
'format' => '$1 $2 $3',
Expand All @@ -252,7 +273,7 @@
'domesticCarrierCodeFormattingRule' => '',
'nationalPrefixOptionalWhenFormatting' => true,
),
3 =>
4 =>
array (
'pattern' => '(\\d)(\\d{2})(\\d{4})(\\d{4})',
'format' => '$1 $2 $3 $4',
Expand All @@ -261,7 +282,7 @@
0 => '1(?:33|55|81)',
),
),
4 =>
5 =>
array (
'pattern' => '(\\d)(\\d{3})(\\d{3})(\\d{4})',
'format' => '$1 $2 $3 $4',
Expand Down

0 comments on commit 407bbbb

Please sign in to comment.