Bug 880644 - [SMS/MMS] Auto suggestions returning incorrect results. r=bent

This commit is contained in:
Gregor Wagner 2013-06-13 14:52:40 -07:00
parent 9a2efc7dd2
commit a3152a6fa5
4 changed files with 92 additions and 6 deletions

View File

@ -885,11 +885,22 @@ ContactDB.prototype = {
"Falling back to 'startsWith'.");
}
// not case sensitive
let tmp = options.filterValue.toString().toLowerCase();
let lowerCase = options.filterValue.toString().toLowerCase();
if (key === "tel") {
tmp = PhoneNumberUtils.normalize(tmp, /*numbersOnly*/ true);
let origLength = lowerCase.length;
let tmp = PhoneNumberUtils.normalize(lowerCase, /*numbersOnly*/ true);
if (tmp.length != origLength) {
let NON_SEARCHABLE_CHARS = /[^#+\*\d\s()-]/;
// e.g. number "123". find with "(123)" but not with "123a"
if (tmp === "" || NON_SEARCHABLE_CHARS.test(lowerCase)) {
if (DEBUG) debug("Call continue!");
continue;
}
lowerCase = tmp;
}
}
let range = this._global.IDBKeyRange.bound(tmp, tmp + "\uFFFF");
if (DEBUG) debug("lowerCase: " + lowerCase);
let range = this._global.IDBKeyRange.bound(lowerCase, lowerCase + "\uFFFF");
let index = store.index(key + "LowerCase");
request = index.mozGetAll(range, limit);
}

View File

@ -1425,6 +1425,78 @@ var steps = [
};
req.onerror = onFailure;
},
function () {
ok(true, "Testing numbersOnly search");
createResult1 = new mozContact();
createResult1.init({ givenName: ["aaaaaaaaa"], tel: [{ value: "1234567890"}]});
req = navigator.mozContacts.save(createResult1);
req.onsuccess = function () {
ok(createResult1.id, "The contact now has an ID.");
next();
};
req.onerror = onFailure;
},
function () {
ok(true, "Test numbersOnly search");
var options = {filterBy: ["givenName", "tel"],
filterOp: "contains",
filterValue: "a"};
req = mozContacts.find(options);
req.onsuccess = function () {
ok(req.result.length == 1, "1 Entry.");
checkContacts(req.result[0], createResult1);
next();
}
req.onerror = onFailure;
},
function () {
ok(true, "Test numbersOnly search");
var options = {filterBy: ["givenName", "tel"],
filterOp: "contains",
filterValue: "b"};
req = mozContacts.find(options);
req.onsuccess = function () {
ok(req.result.length == 0, "0 Entries.");
next();
}
req.onerror = onFailure;
},
function () {
ok(true, "Test numbersOnly search");
var options = {filterBy: ["givenName", "tel"],
filterOp: "contains",
filterValue: "1a"};
req = mozContacts.find(options);
req.onsuccess = function () {
ok(req.result.length == 0, "0 Entries.");
next();
}
req.onerror = onFailure;
},
function () {
ok(true, "Test numbersOnly search");
var options = {filterBy: ["givenName", "tel"],
filterOp: "contains",
filterValue: "1(23)"};
req = mozContacts.find(options);
req.onsuccess = function () {
ok(req.result.length == 1, "1 Entry.");
next();
}
req.onerror = onFailure;
},
function () {
ok(true, "Test numbersOnly search");
var options = {filterBy: ["givenName", "tel"],
filterOp: "contains",
filterValue: "1(23)a"};
req = mozContacts.find(options);
req.onsuccess = function () {
ok(req.result.length == 0, "0 Entries.");
next();
}
req.onerror = onFailure;
},
function () {
ok(true, "Deleting database");
req = mozContacts.clear()

View File

@ -92,9 +92,9 @@ this.PhoneNumberUtils = {
return isPlain;
},
normalize: function Normalize(aNumber) {
var normalized = PhoneNumber.Normalize(aNumber);
if (DEBUG) debug("normalize(" + aNumber + "): " + normalized);
normalize: function Normalize(aNumber, aNumbersOnly) {
var normalized = PhoneNumber.Normalize(aNumber, aNumbersOnly);
if (DEBUG) debug("normalize(" + aNumber + "): " + normalized + ", " + aNumbersOnly);
return normalized;
}
};

View File

@ -47,5 +47,8 @@ function ParseWithMcc(dial, mcc) {
CantParseWithMcc("1234", 123);
ParseWithMcc("4165555555", 302);
is(PhoneNumberUtils.normalize("123abc", true), "123", "NumbersOnly");
is(PhoneNumberUtils.normalize("123abc", false), "123222", "NumbersOnly");
</script>
</window>