Bug 1433876 - Don't assume countries have sub_keys in FormAutofillUtils. r=johannh draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 07 Feb 2018 22:22:53 -0800
changeset 786348 fcdfda41a46fc13e18e7ecbf881ce8ddd1bb89eb
parent 786347 c52c0984afaef7e1c9f9bc87aa6eea8bba541609
child 786349 c8bc120e9aac1abd5fb8e83266e7bd0368292c77
push id107436
push usermozilla@noorenberghe.ca
push dateSun, 22 Apr 2018 23:20:13 +0000
reviewersjohannh
bugs1433876
milestone61.0a1
Bug 1433876 - Don't assume countries have sub_keys in FormAutofillUtils. r=johannh MozReview-Commit-ID: DDgvSqB8fKq
browser/extensions/formautofill/FormAutofillUtils.jsm
--- a/browser/extensions/formautofill/FormAutofillUtils.jsm
+++ b/browser/extensions/formautofill/FormAutofillUtils.jsm
@@ -597,16 +597,20 @@ this.FormAutofillUtils = {
    * @returns {string} The matching sub-region abbreviation.
    */
   getAbbreviatedSubregionName(subregionValues, country) {
     let values = Array.isArray(subregionValues) ? subregionValues : [subregionValues];
 
     let collators = this.getCollators(country);
     for (let metadata of this.getCountryAddressDataWithLocales(country)) {
       let {sub_keys: subKeys, sub_names: subNames, sub_lnames: subLnames} = metadata;
+      if (!subKeys) {
+        // Not all regions have sub_keys. e.g. DE
+        continue;
+      }
       // Apply sub_lnames if sub_names does not exist
       subNames = subNames || subLnames;
 
       let speculatedSubIndexes = [];
       for (const val of values) {
         let identifiedValue = this.identifyValue(subKeys, subNames, val, collators);
         if (identifiedValue) {
           return identifiedValue;
@@ -660,16 +664,20 @@ this.FormAutofillUtils = {
         let {country} = address;
         let identifiedValue = this.getAbbreviatedSubregionName([value], country);
         // No point going any further if we cannot identify value from address level 1
         if (!identifiedValue) {
           return null;
         }
         for (let dataset of this.getCountryAddressDataWithLocales(country)) {
           let keys = dataset.sub_keys;
+          if (!keys) {
+            // Not all regions have sub_keys. e.g. DE
+            continue;
+          }
           // Apply sub_lnames if sub_names does not exist
           let names = dataset.sub_names || dataset.sub_lnames;
 
           // Go through options one by one to find a match.
           // Also check if any option contain the address-level1 key.
           let pattern = new RegExp("\\b" + this.escapeRegExp(identifiedValue) + "\\b", "i");
           for (let option of selectEl.options) {
             let optionValue = this.identifyValue(keys, names, option.value, collators);