Bug 1136211 - SMS cannot be sent to a 15-digit phone number (such as an iNum) which doesn't have a territory id. r=mhenretty

This commit is contained in:
Gregor Wagner 2015-03-31 14:56:05 -07:00
parent e2fe078367
commit a5d081e3d0
3 changed files with 64 additions and 6 deletions

View File

@ -306,8 +306,9 @@ this.PhoneNumber = (function (dataBase) {
// Remove formating characters and whitespace.
number = PhoneNumberNormalizer.Normalize(number);
// If there is no defaultRegion, we can't parse international access codes.
if (!defaultRegion && number[0] !== '+')
// If there is no defaultRegion or the defaultRegion is the global region,
// we can't parse international access codes.
if ((!defaultRegion || defaultRegion === '001') && number[0] !== '+')
return null;
// Detect and strip leading '+'.
@ -317,6 +318,11 @@ this.PhoneNumber = (function (dataBase) {
// Lookup the meta data for the given region.
var md = FindMetaDataForRegion(defaultRegion.toUpperCase());
if (!md) {
dump("Couldn't find Meta Data for region: " + defaultRegion + "\n");
return null;
}
// See if the number starts with an international prefix, and if the
// number resulting from stripping the code is valid, then remove the
// prefix and flag the number as international.

View File

@ -29,8 +29,14 @@ XPCOMUtils.defineLazyServiceGetter(this, "gIccService",
#endif
this.PhoneNumberUtils = {
init: function() {
initParent: function() {
ppmm.addMessageListener(["PhoneNumberService:FuzzyMatch"], this);
this._countryNameCache = Object.create(null);
},
initChild: function () {
this._countryNameCache = Object.create(null);
},
// 1. See whether we have a network mcc
// 2. If we don't have that, look for the simcard mcc
@ -131,13 +137,31 @@ this.PhoneNumberUtils = {
},
parseWithMCC: function(aNumber, aMCC) {
if (DEBUG) debug("parseWithMCC " + aNumber + ", " + aMCC);
let countryName = MCC_ISO3166_TABLE[aMCC];
if (DEBUG) debug("found country name: " + countryName);
return PhoneNumber.Parse(aNumber, countryName);
},
parseWithCountryName: function(aNumber, countryName) {
return PhoneNumber.Parse(aNumber, countryName);
parseWithCountryName: function(aNumber, aCountryName) {
if (this._countryNameCache[aCountryName]) {
return PhoneNumber.Parse(aNumber, aCountryName);
}
if (Object.keys(this._countryNameCache).length === 0) {
// populate the cache
let keys = Object.keys(MCC_ISO3166_TABLE);
for (let i = 0; i < keys.length; i++) {
this._countryNameCache[MCC_ISO3166_TABLE[keys[i]]] = true;
}
}
if (!this._countryNameCache[aCountryName]) {
dump("Couldn't find country name: " + aCountryName + "\n");
return null;
}
return PhoneNumber.Parse(aNumber, aCountryName);
},
isPlainPhoneNumber: function isPlainPhoneNumber(aNumber) {
@ -205,6 +229,8 @@ if (inParent) {
XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
"@mozilla.org/parentprocessmessagemanager;1",
"nsIMessageListenerManager");
PhoneNumberUtils.init();
PhoneNumberUtils.initParent();
} else {
PhoneNumberUtils.initChild();
}

View File

@ -47,6 +47,26 @@ function ParseWithMcc(dial, mcc) {
}
}
function ParseWithCountryName(dial, countryName) {
var result = PhoneNumberUtils.parseWithCountryName(dial, countryName);
if (result) {
ok(true, "Parses!\n");
} else {
ok(false, "Should Parse");
dump("expected: parses");
}
}
function CantParseWithCountryName(dial, countryName) {
var result = PhoneNumberUtils.parseWithCountryName(dial, countryName);
if (result) {
ok(false, "Should not Parse");
dump("expected: does not parse!\n");
} else {
ok(true, "Expected Parsing error!\n");
}
}
function FuzzyMatch(number1, number2, expect) {
var result = PhoneNumberUtils.fuzzyMatch(number1, number2);
is(result, expect, "FuzzyMatch OK!");
@ -56,6 +76,12 @@ function FuzzyMatch(number1, number2, expect) {
CantParseWithMcc("1234", 123);
ParseWithMcc("4165555555", 302);
ParseWithCountryName("4155123456", "US");
CantParseWithCountryName("4155123456", "001");
CantParseWithCountryName("4155123456", "XXY");
ParseWithCountryName("4155123456", "US");
is(PhoneNumberUtils.normalize("123abc", true), "123", "NumbersOnly");
is(PhoneNumberUtils.normalize("123abc", false), "123222", "NumbersOnly");