Skip to content

Commit

Permalink
Strip extension before appending formatted extension
Browse files Browse the repository at this point in the history
  • Loading branch information
giggsey committed Jan 15, 2025
1 parent cc9a82b commit 0474ef7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/PhoneNumberUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions tests/core/PhoneNumberUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 0474ef7

Please sign in to comment.