Bug 1642546 - Fix failure parsing vCard TEL lines with multiple types specified. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 02 Jun 2020 17:05:29 +1200
changeset 29757 7ad149896c421b7c8559794e1e6e3cc24cac06ad
parent 29756 f00e8c7891ad452137199920c59020d121844069
child 29758 4c4de61a34a4540e3cc6eca0cba41f3cd6fe1ad6
push id17517
push usergeoff@darktrojan.net
push dateWed, 03 Jun 2020 05:06:57 +0000
treeherdercomm-central@cf52a9080e3f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1642546
Bug 1642546 - Fix failure parsing vCard TEL lines with multiple types specified. r=mkmelin
mailnews/addrbook/jsaddrbook/VCardUtils.jsm
mailnews/addrbook/test/unit/test_vCard.js
--- a/mailnews/addrbook/jsaddrbook/VCardUtils.jsm
+++ b/mailnews/addrbook/jsaddrbook/VCardUtils.jsm
@@ -19,24 +19,36 @@ var VCardUtils = {
       Ci.nsIAbCard
     );
 
     for (let [name, params, , value] of properties) {
       if (name == "uid") {
         abCard.UID = value;
         continue;
       }
-      if (["adr", "tel"].includes(name)) {
-        if (
-          params.type &&
-          ["home", "work", "cell"].includes(params.type.toLowerCase())
-        ) {
-          name = `${name}.${params.type.toLowerCase()}`;
+      if (params.type) {
+        if (Array.isArray(params.type)) {
+          params.type = params.type.map(t => t.toLowerCase());
         } else {
-          name = `${name}.work`;
+          params.type = [params.type.toLowerCase()];
+        }
+      } else {
+        params.type = [];
+      }
+
+      if (name == "adr") {
+        name = params.type.includes("home") ? "adr.home" : "adr.work";
+      }
+      if (name == "tel") {
+        name = "tel.work";
+        for (let t of params.type) {
+          if (["home", "work", "cell", "pager", "fax"].includes(t)) {
+            name = `tel.${t}`;
+            break;
+          }
         }
       }
       if (name in propertyMap) {
         for (let [abPropName, abPropValue] of Object.entries(
           propertyMap[name].toAbCard(value)
         )) {
           if (abPropValue) {
             abCard.setProperty(abPropName, abPropValue);
--- a/mailnews/addrbook/test/unit/test_vCard.js
+++ b/mailnews/addrbook/test/unit/test_vCard.js
@@ -62,16 +62,27 @@ add_task(function testVCardToAbCard() {
     HomeAddress: "123 Main Street",
     HomeCity: "Any Town",
     HomeState: "CA",
     HomeZipCode: "91921-1234",
     HomeCountry: "U.S.A.",
   });
   // Phone
   check("TEL:11-2358-13-21", { WorkPhone: "11-2358-13-21" });
+  check("TEL;TYPE=work:11-2358-13-21", { WorkPhone: "11-2358-13-21" });
+  check("TEL;TYPE=home:11-2358-13-21", { HomePhone: "11-2358-13-21" });
+  check("TEL;TYPE=cell:11-2358-13-21", { CellularNumber: "11-2358-13-21" });
+  check("TEL;TYPE=pager:11-2358-13-21", { PagerNumber: "11-2358-13-21" });
+  check("TEL;TYPE=fax:11-2358-13-21", { FaxNumber: "11-2358-13-21" });
+
+  check("TEL;TYPE=work;PREF:11-2358-13-21", { WorkPhone: "11-2358-13-21" });
+  check("TEL;TYPE=work,cell:11-2358-13-21", { WorkPhone: "11-2358-13-21" });
+  check("TEL;TYPE=work;TYPE=cell:11-2358-13-21", {
+    WorkPhone: "11-2358-13-21",
+  });
   check("TEL;TYPE=work;VALUE=TEXT:11-2358-13-21", {
     WorkPhone: "11-2358-13-21",
   });
   check("TEL;TYPE=home;VALUE=TEXT:011-2358-13-21", {
     HomePhone: "011-2358-13-21",
   });
   check(
     "TEL;TYPE=work;VALUE=TEXT:11-2358-13-21\r\nTEL;TYPE=home;VALUE=TEXT:011-2358-13-21",