Bug 818507 - Importing SIM contacts stays stuck on spinner. r=gal, a=blocking-basecamp
authorGregor Wagner <anygregor@gmail.com>
Wed, 05 Dec 2012 20:03:27 -0800
changeset 117642 603f662bd692958176980fb5be9e0ad8559af003
parent 117641 be8438b02e2d6c59c14aa3fb5c7b44aae8d3ff42
child 117643 a7e5e06a64ed9893f4fd842cfa1160694bf6b1d4
push id46
push userryanvm@gmail.com
push dateTue, 18 Dec 2012 01:41:29 +0000
reviewersgal, blocking-basecamp
bugs818507
milestone18.0
Bug 818507 - Importing SIM contacts stays stuck on spinner. r=gal, a=blocking-basecamp
dom/phonenumberutils/PhoneNumber.jsm
dom/phonenumberutils/tests/test_phonenumber.xul
--- a/dom/phonenumberutils/PhoneNumber.jsm
+++ b/dom/phonenumberutils/PhoneNumber.jsm
@@ -99,19 +99,33 @@ this.PhoneNumber = (function (dataBase) 
       // Each entry is a string encoded object of the form '["US..', or
       // an array of strings. We don't want to parse the string here
       // to save memory, so we just substring the region identifier
       // and compare it. For arrays, we compare against all region
       // identifiers with that country code. We skip entries that are
       // of type object, because they were already resolved (parsed into
       // an object), and their country code should have been in the cache.
       if (Array.isArray(entry)) {
-        for (var n = 0; n < entry.length; ++n) {
-          if (typeof entry[n] == "string" && entry[n].substr(2,2) == region)
-            return entry[n] = ParseMetaData(countryCode, entry[n]);
+        for (var n = 0; n < entry.length; n++) {
+          if (typeof entry[n] == "string" && entry[n].substr(2,2) == region) {
+            if (n > 0) {
+              // Only the first entry has the formats field set.
+              // Parse the main country if we haven't already and use
+              // the formats field from the main country.
+              if (typeof entry[0] == "string" && entry[0].substr(2,2) == region)
+                entry[0] = ParseMetaData(countryCode, entry[0]);
+              let formats = entry[0].formats;
+              let current = ParseMetaData(countryCode, entry[n]);
+              current.formats = formats;
+              return entry[n] = current;
+            }
+            
+            entry[n] = ParseMetaData(countryCode, entry[n]);
+            return entry[n];
+          }
         }
         continue;
       }
       if (typeof entry == "string" && entry.substr(2,2) == region)
         return dataBase[countryCode] = ParseMetaData(countryCode, entry);
     }
   }
 
--- a/dom/phonenumberutils/tests/test_phonenumber.xul
+++ b/dom/phonenumberutils/tests/test_phonenumber.xul
@@ -37,16 +37,27 @@ function Parse(dial, currentRegion) {
   if (!result) {
   	ok(false, "got: " + dial + " " + currentRegion);
   } else {
   	ok(true, "Parses!\n");
   }
   return result;
 }
 
+function ParseWithIntl(dial, currentRegion) {
+  var result = PhoneNumber.Parse(dial, currentRegion);
+  if (!result) {
+  	ok(false, "got: " + dial + " " + currentRegion);
+  } else {
+    ok(result.internationalNumber, "Has International!");
+  	ok(true, "Parses!\n");
+  }
+  return result;
+}
+
 function Test(dial, currentRegion, nationalNumber, region) {
   var result = Parse(dial, currentRegion);
   if (result.region != region || result.nationalNumber != nationalNumber) {
     ok(false, "expected: " + nationalNumber + " " + region + "got: " + result.nationalNumber + " " + result.region);
   } else {
   	ok(true, "Test ok!");
   }
   return result;
@@ -119,16 +130,36 @@ Parse("023 1234 0000", "AR");
 // Test numbers in Mexico
 Parse("+52 (449)978-0001", "MX");
 Parse("01 (449)978-0001", "MX");
 Parse("(449)978-0001", "MX");
 Parse("+52 1 33 1234-5678", "MX");
 Parse("044 (33) 1234-5678", "MX");
 Parse("045 33 1234-5678", "MX");
 
+
+ParseWithIntl("4031234567", "CA");
+Parse("(416) 585-4319", "CA");
+Parse("647-967-4357", "CA");
+Parse("416-716-8768", "CA");
+Parse("18002684646", "CA");
+Parse("416-445-9119", "CA");
+Parse("1-800-668-6866", "CA");
+Parse("(416) 453-6486", "CA");
+Parse("(647) 268-4778", "CA");
+Parse("647-218-1313", "CA");
+Parse("+1 647-209-4642", "CA");
+Parse("416-559-0133", "CA");
+Parse("+1 647-639-4118", "CA");
+Parse("+12898803664", "CA");
+Parse("780-901-4687", "CA");
+Parse("+14167070550", "CA");
+Parse("+1-647-522-6487", "CA");
+Parse("(416) 877-0880", "CA");
+
 // Test that lots of spaces are ok.
 Parse("0 3   3 3 1   6 0 0 5", "NZ");
 
 // Test omitting the current region. This is only valid when the number starts
 // with a '+'.
 Parse("+64 3 331 6005");
 Parse("+64 3 331 6005", null);