diff --git a/src/PhoneNumberUtil.php b/src/PhoneNumberUtil.php index aac0eb5cf..763499486 100644 --- a/src/PhoneNumberUtil.php +++ b/src/PhoneNumberUtil.php @@ -2776,6 +2776,9 @@ public function formatOutOfCountryKeepingAlphaChars(PhoneNumber $number, $region $regionCode = $this->getRegionCodeForCountryCode($countryCode); // Metadata cannot be null because the country calling code is valid. $metadataForRegion = $this->getMetadataForRegionOrCallingCode($countryCode, $regionCode); + // Strip any extension + $this->maybeStripExtension($formattedNumber); + // Append the formatted extension $this->maybeAppendFormattedExtension( $number, $metadataForRegion, diff --git a/tests/core/PhoneNumberUtilTest.php b/tests/core/PhoneNumberUtilTest.php index 5378707c4..e776d8318 100644 --- a/tests/core/PhoneNumberUtilTest.php +++ b/tests/core/PhoneNumberUtilTest.php @@ -880,6 +880,13 @@ public function testFormatOutOfCountryKeepingAlphaChars() $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumber, RegionCode::BS) ); + // Testing a number with extension. + $alphaNumericNumberWithExtn = $this->phoneUtil->parseAndKeepRawInput('800 SIX-flag ext. 1234', RegionCode::US); + $this->assertEquals( + '0011 1 800 SIX-FLAG extn. 1234', + $this->phoneUtil->formatOutOfCountryKeepingAlphaChars($alphaNumericNumberWithExtn, RegionCode::AU) + ); + // Testing that if the raw input doesn't exist, it is formatted using // formatOutOfCountryCallingNumber. $alphaNumericNumber->clearRawInput();