Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libphonenumber JS API is not able to parse numbers with missing '+' u… #3770

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion javascript/i18n/phonenumbers/phonenumberutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -3852,7 +3852,7 @@ i18n.phonenumbers.PhoneNumberUtil.prototype.maybeExtractCountryCode =
var generalDesc = defaultRegionMetadata.getGeneralDesc();
/** @type {!RegExp} */
var validNumberPattern =
new RegExp(generalDesc.getNationalNumberPatternOrDefault());
new RegExp('^(?:' + generalDesc.getNationalNumberPatternOrDefault() + ')$');
// Passing null since we don't need the carrier code.
this.maybeStripNationalPrefixAndCarrierCode(
potentialNationalNumber, defaultRegionMetadata, null);
Expand Down
18 changes: 18 additions & 0 deletions javascript/i18n/phonenumbers/phonenumberutil_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2758,6 +2758,24 @@ function testMaybeExtractCountryCode() {
} catch (e) {
fail('Should not have thrown an exception: ' + e.toString());
}
number = new i18n.phonenumbers.PhoneNumber();
try {
phoneNumber = '821064588888';
metadata = phoneUtil.getMetadataForRegion(RegionCode.KR);
countryCallingCode = 82;
numberToFill = new goog.string.StringBuffer();
assertEquals(
'Should have extracted the country calling code of the ' +
'region passed in',
countryCallingCode,
phoneUtil.maybeExtractCountryCode(
phoneNumber, metadata, numberToFill, true, number));
assertEquals(
'Did figure out CountryCodeSource correctly',
CCS.FROM_NUMBER_WITHOUT_PLUS_SIGN, number.getCountryCodeSource());
} catch (e) {
fail('Should not have thrown an exception: ' + e.toString());
}
}

function testParseNationalNumber() {
Expand Down
Loading