Bug 1644667 - When setting contact properties, convert values to string. r=mkmelin a=wsmwk
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 10 Jun 2020 22:36:18 +1200
changeset 39379 d9deffe5067f4ef2a1016773bb0137c226804e4a
parent 39378 e81c949b4a229c35678454fb6e6cedc5a4b70707
child 39380 49e5d2a195377ef0466d91ecd172e4ccf444e806
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersmkmelin, wsmwk
bugs1644667
Bug 1644667 - When setting contact properties, convert values to string. r=mkmelin a=wsmwk All values read from the database are strings, but when freshly set by code they are remembered in their original type. Convert them to string for consistency.
mailnews/addrbook/jsaddrbook/AddrBookCard.jsm
--- a/mailnews/addrbook/jsaddrbook/AddrBookCard.jsm
+++ b/mailnews/addrbook/jsaddrbook/AddrBookCard.jsm
@@ -197,29 +197,36 @@ AddrBookCard.prototype = {
         return true;
     }
     throw Components.Exception(
       `${name}: ${value} - not a boolean`,
       Cr.NS_ERROR_NOT_AVAILABLE
     );
   },
   setProperty(name, value) {
-    this._properties.set(name, value);
+    if (value === null || value === undefined) {
+      this._properties.delete(name);
+      return;
+    }
+    if (typeof value == "boolean") {
+      value = value ? "1" : "0";
+    }
+    this._properties.set(name, "" + value);
   },
   setPropertyAsAString(name, value) {
     throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED);
   },
   setPropertyAsAUTF8String(name, value) {
     this.setProperty(name, value);
   },
   setPropertyAsUint32(name, value) {
     this.setProperty(name, value);
   },
   setPropertyAsBool(name, value) {
-    this.setProperty(name, value ? 1 : 0);
+    this.setProperty(name, value ? "1" : "0");
   },
   deleteProperty(name) {
     this._properties.delete(name);
   },
   hasEmailAddress(emailAddress) {
     if (this._properties.get("PrimaryEmail") == emailAddress) {
       return true;
     }