Bug 1642544 - Correctly parse vCard lines that have only one value when multiple values are also valid. r=mkmelin a=wsmwk
authorGeoff Lankow <geoff@darktrojan.net>
Sun, 24 May 2020 21:03:54 +1200
changeset 39323 1a47d65e5ec71059976a8a8eef137654e0b6d337
parent 39322 71067085a23255de547fc7c3d07dce005aa18001
child 39324 bcf0deefc739faf033fb2e97e4bf87a83fc07d54
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersmkmelin, wsmwk
bugs1642544
Bug 1642544 - Correctly parse vCard lines that have only one value when multiple values are also valid. r=mkmelin a=wsmwk
mailnews/addrbook/jsaddrbook/VCardUtils.jsm
mailnews/addrbook/test/unit/test_vCard.js
--- a/mailnews/addrbook/jsaddrbook/VCardUtils.jsm
+++ b/mailnews/addrbook/jsaddrbook/VCardUtils.jsm
@@ -281,25 +281,28 @@ function multiTextProperty(abPropNames, 
         vPropName,
         { ...vPropParams },
         "text",
         abPropNames.map(name => map.get(name) || ""),
       ];
     },
     toAbCard(value) {
       let result = {};
-      if (!Array.isArray(value)) {
+      if (Array.isArray(value)) {
+        for (let abPropName of abPropNames) {
+          let valuePart = value.shift();
+          if (abPropName && valuePart) {
+            result[abPropName] = valuePart;
+          }
+        }
+      } else if (typeof value == "string") {
+        // Only one value was given.
+        result[abPropNames[0]] = value;
+      } else {
         console.warn(`Unexpected value for ${vPropName}: ${value}`);
-        return result;
-      }
-      for (let abPropName of abPropNames) {
-        let valuePart = value.shift();
-        if (abPropName && valuePart) {
-          result[abPropName] = valuePart;
-        }
       }
       return result;
     },
   };
 }
 
 /**
  * Properties we support for conversion between nsIAbCard and vCard.
--- a/mailnews/addrbook/test/unit/test_vCard.js
+++ b/mailnews/addrbook/test/unit/test_vCard.js
@@ -87,16 +87,29 @@ add_task(function testVCardToAbCard() {
     BirthYear: "1983",
   });
   // Anniversary
   check("ANNIVERSARY;VALUE=DATE:20041207", {
     AnniversaryDay: "7",
     AnniversaryMonth: "12",
     AnniversaryYear: "2004",
   });
+
+  // Organization: any number of values is valid here.
+  check("ORG:Acme Widgets, Inc.", {
+    Company: "Acme Widgets, Inc.",
+  });
+  check("ORG:Acme Widgets, Inc.;Manufacturing", {
+    Company: "Acme Widgets, Inc.",
+    Department: "Manufacturing",
+  });
+  check("ORG:Acme Widgets, Inc.;Manufacturing;Thingamies", {
+    Company: "Acme Widgets, Inc.",
+    Department: "Manufacturing",
+  });
 });
 
 add_task(function testModifyVCard() {
   function check(
     inVCard,
     newProps,
     expectedLines = [],
     unexpectedPrefixes = []