Bug 1652984 - Part 2: Fix calIcalProperty.valueAsIcalString for GEO field. r=darktrojan
authorPing Chen <remotenonsense@gmail.com>
Fri, 27 Nov 2020 12:56:00 +0200
changeset 95755 3a8db8b969124bf38f4b090a8a6adb9ea03b28f8
parent 95754 665f3d0ebe308184817fc91fffcafde9bad450d5
child 95756 5eefd7090060826c39c79ea62a81c8ad76e5f6f5
child 95758 0afc728a0ae315641257a6b3edff6a9e416f0ff0
push id12266
push useralessandro@thunderbird.net
push dateFri, 27 Nov 2020 18:08:17 +0000
treeherdertry-comm-central@8c7cdfd510a2 [default view] [failures only]
reviewersdarktrojan
bugs1652984
Bug 1652984 - Part 2: Fix calIcalProperty.valueAsIcalString for GEO field. r=darktrojan Differential Revision: https://phabricator.services.mozilla.com/D97723
calendar/base/backend/icaljs/calICSService.js
calendar/test/unit/test_ics_service.js
--- a/calendar/base/backend/icaljs/calICSService.js
+++ b/calendar/base/backend/icaljs/calICSService.js
@@ -47,16 +47,26 @@ calIcalProperty.prototype = {
     if (this.innerObject.type == "text") {
       this.innerObject.setValue(val);
       return;
     }
     this.valueAsIcalString = val;
   },
 
   get valueAsIcalString() {
+    let propertyStr = this.innerObject.toICALString();
+    if (propertyStr.match(/:/g).length == 1) {
+      // For property containing only one colon, e.g. `GEO:latitude;longitude`,
+      // the left hand side must be the property name, the right hand side must
+      // be property value.
+      return propertyStr.slice(propertyStr.indexOf(":") + 1);
+    }
+    // For property containing many or no colons, retrieve the property value
+    // according to its type. An example is
+    // `ATTENDEE;MEMBER="mailto:foo@example.com": mailto:bar@example.com`
     let type = this.innerObject.type;
     return this.innerObject
       .getValues()
       .map(val => {
         if (type == "text") {
           return ICAL.stringify.value(val, type, ICAL.design.icalendar);
         } else if (typeof val == "number" || typeof val == "string") {
           return val;
--- a/calendar/test/unit/test_ics_service.js
+++ b/calendar/test/unit/test_ics_service.js
@@ -177,16 +177,21 @@ function test_icalproperty() {
   equal(prop.valueAsIcalString, "A\\nB");
   equal(prop.valueAsDatetime, null);
 
   prop = svc.createIcalProperty("DESCRIPTION");
   prop.value = "A\\nB";
   equal(prop.value, "A\\nB");
   equal(prop.valueAsIcalString, "A\\\\nB");
   equal(prop.valueAsDatetime, null);
+
+  prop = svc.createIcalProperty("GEO");
+  prop.value = "43.4913662534171;12.085559129715";
+  equal(prop.value, "43.4913662534171;12.085559129715");
+  equal(prop.valueAsIcalString, "43.4913662534171;12.085559129715");
 }
 
 function test_icalcomponent() {
   let svc = cal.getIcsService();
   let event = svc.createIcalComponent("VEVENT");
   let alarm = svc.createIcalComponent("VALARM");
   event.addSubcomponent(alarm);