@@ -1781,15 +1781,19 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.hasValidCountryCallingCode_ =
17811781i18n . phonenumbers . PhoneNumberUtil . prototype . format =
17821782 function ( number , numberFormat ) {
17831783
1784- if ( number . getNationalNumber ( ) == 0 && number . hasRawInput ( ) ) {
1785- // Unparseable numbers that kept their raw input just use that.
1786- // This is the only case where a number can be formatted as E164 without a
1787- // leading '+' symbol (but the original number wasn't parseable anyway).
1788- // TODO: Consider removing the 'if' above so that unparseable strings
1789- // without raw input format to the empty string instead of "+00"
1784+ if ( number . getNationalNumber ( ) == 0 && number . hasRawInput ( ) ) {
1785+ // Unparseable numbers that kept their raw input just use that, unless
1786+ // default country was specified and the format is E164. In that case, we
1787+ // prepend the raw input with the country code.
17901788 /** @type {string } */
1791- var rawInput = number . getRawInputOrDefault ( ) ;
1792- if ( rawInput . length > 0 ) {
1789+ const rawInput = number . getRawInputOrDefault ( ) ;
1790+ if ( rawInput . length > 0 && number . hasCountryCode ( )
1791+ && number . getCountryCodeSource ( ) == i18n . phonenumbers . PhoneNumber . CountryCodeSource . FROM_DEFAULT_COUNTRY
1792+ && numberFormat == i18n . phonenumbers . PhoneNumberFormat . E164 ) {
1793+ const countryCallingCode = number . getCountryCodeOrDefault ( ) ;
1794+ let formattedNumber = rawInput ;
1795+ return this . prefixNumberWithCountryCallingCode_ ( countryCallingCode , numberFormat , formattedNumber , '' ) ;
1796+ } else if ( rawInput . length > 0 || ! number . hasCountryCode ( ) ) {
17931797 return rawInput ;
17941798 }
17951799 }
0 commit comments