Bug 1652984 - Part 2: Fix calIcalProperty.valueAsIcalString for GEO field. r=darktrojan
Differential Revision:
https://phabricator.services.mozilla.com/D97723
--- 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);