Bug 1378694 - Make sure no null pointer before trimming string in FormAutofillUtils.toOneLineAddress. r=lchang
MozReview-Commit-ID: KAelqPAMrwY
--- a/browser/extensions/formautofill/FormAutofillUtils.jsm
+++ b/browser/extensions/formautofill/FormAutofillUtils.jsm
@@ -65,20 +65,20 @@ this.FormAutofillUtils = {
// white space is a temporary solution.
return " ";
},
toOneLineAddress(address, delimiter = "\n") {
let array = typeof address == "string" ? address.split(delimiter) : address;
if (!Array.isArray(array)) {
- return null;
+ return "";
}
return array
- .map(s => s.trim())
+ .map(s => s ? s.trim() : "")
.filter(s => s)
.join(this.getAddressSeparator());
},
defineLazyLogGetter(scope, logPrefix) {
XPCOMUtils.defineLazyGetter(scope, "log", () => {
let ConsoleAPI = Cu.import("resource://gre/modules/Console.jsm", {}).ConsoleAPI;
return new ConsoleAPI({
--- a/browser/extensions/formautofill/content/manageProfiles.js
+++ b/browser/extensions/formautofill/content/manageProfiles.js
@@ -136,29 +136,29 @@ ManageProfileDialog.prototype = {
* @returns {string}
*/
getAddressLabel(address) {
// TODO: Implement a smarter way for deciding what to display
// as option text. Possibly improve the algorithm in
// ProfileAutoCompleteResult.jsm and reuse it here.
const fieldOrder = [
"name",
- "street-address", // Street address
+ "-moz-street-address-one-line", // Street address
"address-level2", // City/Town
"organization", // Company or organization name
"address-level1", // Province/State (Standardized code if possible)
"country-name", // Country name
"postal-code", // Postal code
"tel", // Phone number
"email", // Email address
];
let parts = [];
if (address["street-address"]) {
- address["street-address"] = FormAutofillUtils.toOneLineAddress(
+ address["-moz-street-address-one-line"] = FormAutofillUtils.toOneLineAddress(
address["street-address"]
);
}
for (const fieldName of fieldOrder) {
let string = address[fieldName];
if (string) {
parts.push(string);
}
--- a/browser/extensions/formautofill/test/unit/test_toOneLineAddress.js
+++ b/browser/extensions/formautofill/test/unit/test_toOneLineAddress.js
@@ -13,16 +13,20 @@ add_task(async function test_getCategori
strings: ["A", "B", "", "D"],
expectedValue: "A B D",
},
{
strings: ["", "B", "", "D"],
expectedValue: "B D",
},
{
+ strings: [null, "B", " ", "D"],
+ expectedValue: "B D",
+ },
+ {
strings: "A B C",
expectedValue: "A B C",
},
{
strings: "A\nB\n\n\nC",
expectedValue: "A B C",
},
{
@@ -33,20 +37,24 @@ add_task(async function test_getCategori
strings: "A-B-C",
expectedValue: "A B C",
delimiter: "-",
},
{
strings: "A B\n \nC",
expectedValue: "A B C",
},
+ {
+ strings: null,
+ expectedValue: "",
+ },
];
for (let tc of TEST_CASES) {
let result;
if (tc.delimiter) {
result = FormAutofillUtils.toOneLineAddress(tc.strings, tc.delimiter);
} else {
result = FormAutofillUtils.toOneLineAddress(tc.strings);
}
- Assert.deepEqual(result, tc.expectedValue);
+ Assert.equal(result, tc.expectedValue);
}
});