Bug 1391149 - [Form Autofill] Avoid exposing fields with empty value from the storage. r=steveck a=gchang
authorLuke Chang <lchang@mozilla.com>
Thu, 17 Aug 2017 12:38:42 +0800
changeset 424102 1c08a2f4d2fc14e2a88915a2bd8f033f04c058ab
parent 424101 fbef00b40b98333a637211cd284db9e3f5348f07
child 424103 12809a8ce21a7b10c7a4e54baa9ae742c176de87
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssteveck, gchang
bugs1391149
milestone56.0
Bug 1391149 - [Form Autofill] Avoid exposing fields with empty value from the storage. r=steveck a=gchang MozReview-Commit-ID: 8WHCFNNckO4
browser/extensions/formautofill/ProfileStorage.jsm
browser/extensions/formautofill/test/unit/test_transformFields.js
--- a/browser/extensions/formautofill/ProfileStorage.jsm
+++ b/browser/extensions/formautofill/ProfileStorage.jsm
@@ -1079,17 +1079,19 @@ class AutofillRecords {
 
   /**
    * Internal helper functions.
    */
 
   _clone(record) {
     let result = {};
     for (let key in record) {
-      if (!key.startsWith("_")) {
+      // Do not expose hidden fields and fields with empty value (mainly used
+      // as placeholders of the computed fields).
+      if (!key.startsWith("_") && record[key] !== "") {
         result[key] = record[key];
       }
     }
     return result;
   }
 
   _findByGUID(guid, {includeDeleted = false} = {}) {
     let found = this._findIndexByGUID(guid, {includeDeleted});
@@ -1168,18 +1170,18 @@ class Addresses extends AutofillRecords 
   constructor(store) {
     super(store, "addresses", VALID_ADDRESS_FIELDS, VALID_ADDRESS_COMPUTED_FIELDS, ADDRESS_SCHEMA_VERSION);
   }
 
   _recordReadProcessor(address) {
     // TODO: We only support US in MVP so hide the field if it's not. We
     //       are going to support more countries in bug 1370193.
     if (address.country && address.country != "US") {
-      address["country-name"] = "";
       delete address.country;
+      delete address["country-name"];
     }
   }
 
   _computeFields(address) {
     // NOTE: Remember to bump the schema version number if any of the existing
     //       computing algorithm changes. (No need to bump when just adding new
     //       computed fields)
 
--- a/browser/extensions/formautofill/test/unit/test_transformFields.js
+++ b/browser/extensions/formautofill/test/unit/test_transformFields.js
@@ -72,17 +72,17 @@ const ADDRESS_COMPUTE_TESTCASES = [
   {
     description: "\"street-address\" with multiple lines but line2 is omitted",
     address: {
       "street-address": "line1\n\nline3",
     },
     expectedResult: {
       "street-address": "line1\n\nline3",
       "address-line1": "line1",
-      "address-line2": "",
+      "address-line2": undefined,
       "address-line3": "line3",
     },
   },
   {
     description: "\"street-address\" with 4 lines",
     address: {
       "street-address": "line1\nline2\nline3\nline4",
     },
@@ -96,17 +96,17 @@ const ADDRESS_COMPUTE_TESTCASES = [
   {
     description: "\"street-address\" with blank lines",
     address: {
       "street-address": "line1\n \nline3\n \nline5",
     },
     expectedResult: {
       "street-address": "line1\n \nline3\n \nline5",
       "address-line1": "line1",
-      "address-line2": "",
+      "address-line2": undefined,
       "address-line3": "line3 line5",
     },
   },
 
   // Country
   {
     description: "Has \"country\"",
     address: {
@@ -138,20 +138,20 @@ const ADDRESS_COMPUTE_TESTCASES = [
     description: "\"tel\" with TW country code (the components won't be parsed)",
     address: {
       "tel": "+886212345678",
     },
     expectedResult: {
       "tel": "+886212345678",
       "tel-country-code": "+886",
       "tel-national": "0212345678",
-      "tel-area-code": "",
-      "tel-local": "",
-      "tel-local-prefix": "",
-      "tel-local-suffix": "",
+      "tel-area-code": undefined,
+      "tel-local": undefined,
+      "tel-local-prefix": undefined,
+      "tel-local-suffix": undefined,
     },
   },
   {
     description: "\"tel\" without country code so use \"US\" as default resion",
     address: {
       "tel": "6172535702",
     },
     expectedResult: {
@@ -169,35 +169,35 @@ const ADDRESS_COMPUTE_TESTCASES = [
     address: {
       "tel": "0212345678",
       "country": "TW",
     },
     expectedResult: {
       "tel": "+886212345678",
       "tel-country-code": "+886",
       "tel-national": "0212345678",
-      "tel-area-code": "",
-      "tel-local": "",
-      "tel-local-prefix": "",
-      "tel-local-suffix": "",
+      "tel-area-code": undefined,
+      "tel-local": undefined,
+      "tel-local-prefix": undefined,
+      "tel-local-suffix": undefined,
     },
   },
   {
     description: "\"tel\" can't be parsed so leave it as-is",
     address: {
       "tel": "12345",
     },
     expectedResult: {
       "tel": "12345",
-      "tel-country-code": "",
+      "tel-country-code": undefined,
       "tel-national": "12345",
-      "tel-area-code": "",
-      "tel-local": "",
-      "tel-local-prefix": "",
-      "tel-local-suffix": "",
+      "tel-area-code": undefined,
+      "tel-local": undefined,
+      "tel-local-prefix": undefined,
+      "tel-local-suffix": undefined,
     },
   },
 ];
 
 const ADDRESS_NORMALIZE_TESTCASES = [
   // Empty
   {
     description: "Empty address",
@@ -343,27 +343,27 @@ const ADDRESS_NORMALIZE_TESTCASES = [
   },
   {
     description: "Has \"country-name\" as part of a word",
     address: {
       "country-name": "TRUST",
     },
     expectedResult: {
       "country": undefined,
-      "country-name": "",
+      "country-name": undefined,
     },
   },
   {
     description: "Has unknown \"country-name\"",
     address: {
       "country-name": "unknown country name",
     },
     expectedResult: {
       "country": undefined,
-      "country-name": "",
+      "country-name": undefined,
     },
   },
   {
     description: "Has \"country\" and unknown \"country-name\"",
     address: {
       "country": "us",
       "country-name": "unknown country name",
     },
@@ -375,27 +375,27 @@ const ADDRESS_NORMALIZE_TESTCASES = [
   {
     description: "Has \"country-name\" and unknown \"country\"",
     address: {
       "country": "AA",
       "country-name": "united states",
     },
     expectedResult: {
       "country": undefined,
-      "country-name": "",
+      "country-name": undefined,
     },
   },
   {
     description: "Has unsupported \"country\"",
     address: {
       "country": "CA",
     },
     expectedResult: {
       "country": undefined,
-      "country-name": "",
+      "country-name": undefined,
     },
   },
 
   // Tel
   {
     description: "Has \"tel\" with country code",
     address: {
       "tel": "+16172535702",