Bug 869273 - Update PhoneNumber.jsm from upstream. r=gwagner, a=tef+
authorReuben Morais <reuben.morais@gmail.com>
Tue, 07 May 2013 15:09:01 -0700
changeset 119371 877ec749673c9a8238525d8a036eedaf267bbbbf
parent 119370 50726fbdc25e4ead305d42d22864e9fd28239118
child 119372 9c18bee79be07fad36874bf11eefd2fea3f3e17d
push id800
push userryanvm@gmail.com
push dateMon, 13 May 2013 22:17:28 +0000
reviewersgwagner, tef
bugs869273
milestone18.0
Bug 869273 - Update PhoneNumber.jsm from upstream. r=gwagner, a=tef+
dom/phonenumberutils/PhoneNumber.jsm
--- a/dom/phonenumberutils/PhoneNumber.jsm
+++ b/dom/phonenumberutils/PhoneNumber.jsm
@@ -71,16 +71,19 @@ this.PhoneNumber = (function (dataBase) 
     regionCache[md.region] = md;
     return md;
   }
 
   // Parse string encoded format data into a convenient object
   // representation.
   function ParseFormat(md) {
     var formats = md.formats;
+    if (!formats) {
+      return null;
+    }
     // Bail if we already parsed the format definitions.
     if (!(Array.isArray(formats[0])))
       return;
     for (var n = 0; n < formats.length; ++n) {
       formats[n] = ParseArray(formats[n],
                               FORMAT_ENCODING,
                               {});
     }
@@ -133,16 +136,19 @@ this.PhoneNumber = (function (dataBase) 
 
   // Format a national number for a given region. The boolean flag "intl"
   // indicates whether we want the national or international format.
   function FormatNumber(regionMetaData, number, intl) {
     // We lazily parse the format description in the meta data for the region,
     // so make sure to parse it now if we haven't already done so.
     ParseFormat(regionMetaData);
     var formats = regionMetaData.formats;
+    if (!formats) {
+      return null;
+    }
     for (var n = 0; n < formats.length; ++n) {
       var format = formats[n];
       // The leading digits field is optional. If we don't have it, just
       // use the matching pattern to qualify numbers.
       if (format.leadingDigits && !format.leadingDigits.test(number))
         continue;
       if (!format.pattern.test(number))
         continue;
@@ -167,22 +173,24 @@ this.PhoneNumber = (function (dataBase) 
         var nationalPrefixFormattingRule = regionMetaData.nationalPrefixFormattingRule;
         if (format.nationalPrefixFormattingRule)
           nationalPrefixFormattingRule = format.nationalPrefixFormattingRule;
         if (nationalPrefixFormattingRule) {
           // The prefix formatting rule contains two magic markers, "$NP" and "$FG".
           // "$NP" will be replaced by the national prefix, and "$FG" with the
           // first group of numbers.
           var match = number.match(SPLIT_FIRST_GROUP);
-          var firstGroup = match[1];
-          var rest = match[2];
-          var prefix = nationalPrefixFormattingRule;
-          prefix = prefix.replace("$NP", regionMetaData.nationalPrefix);
-          prefix = prefix.replace("$FG", firstGroup);
-          number = prefix + rest;
+          if (match) {
+            var firstGroup = match[1];
+            var rest = match[2];
+            var prefix = nationalPrefixFormattingRule;
+            prefix = prefix.replace("$NP", regionMetaData.nationalPrefix);
+            prefix = prefix.replace("$FG", firstGroup);
+            number = prefix + rest;
+          }
         }
       }
       return (number == "NA") ? null : number;
     }
     return null;
   }
 
   function NationalNumber(regionMetaData, number) {