зеркало из https://github.com/mozilla/pjs.git
Define the escaping behaviour of ical properties, to make sure we do the right thing with escaped values in ical calendars.
bug 307948, r=dmose
This commit is contained in:
Родитель
da608b74fc
Коммит
fa7e36310f
|
@ -168,7 +168,19 @@ interface calIIcalComponent : nsISupports
|
|||
[scriptable,uuid(17349a10-5d80-47fa-9bea-f22957357675)]
|
||||
interface calIIcalProperty : nsISupports
|
||||
{
|
||||
attribute AUTF8String stringValue;
|
||||
/**
|
||||
* The value of the property as string.
|
||||
* The exception for properties of TEXT or X- type, those will be unescaped
|
||||
* when getting, and also expects an unescaped string when setting.
|
||||
* Datetime, numeric and other non-text types are represented as ical string
|
||||
*/
|
||||
attribute AUTF8String value;
|
||||
|
||||
/**
|
||||
* The value of the property in (escaped) ical format.
|
||||
*/
|
||||
attribute AUTF8String valueAsIcalString;
|
||||
|
||||
// XXX attribute AUTF8String stringValueWithParams; ?
|
||||
readonly attribute AUTF8String propertyName;
|
||||
|
||||
|
|
|
@ -181,7 +181,7 @@ calEvent.prototype = {
|
|||
try {
|
||||
if (!this.eventPromotedProps[iprop.name]) {
|
||||
var icalprop = icssvc.createIcalProperty(iprop.name);
|
||||
icalprop.stringValue = iprop.value;
|
||||
icalprop.value = iprop.value;
|
||||
icalcomp.addProperty(icalprop);
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
|
@ -67,12 +67,26 @@ calIcalProperty::GetIcalProperty()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::GetStringValue(nsACString &str)
|
||||
calIcalProperty::GetValue(nsACString &str)
|
||||
{
|
||||
const char *icalstr = icalproperty_get_value_as_string(mProperty);
|
||||
icalvalue_kind kind = icalproperty_kind_to_value_kind(icalproperty_isa(mProperty));
|
||||
|
||||
const char *icalstr;
|
||||
if (kind == ICAL_TEXT_VALUE) {
|
||||
icalvalue *v = icalproperty_get_value(mProperty);
|
||||
icalstr = icalvalue_get_text(v);
|
||||
} else if (kind == ICAL_X_VALUE) {
|
||||
icalvalue *v = icalproperty_get_value(mProperty);
|
||||
icalstr = icalvalue_get_x(v);
|
||||
} else {
|
||||
icalstr = icalproperty_get_value_as_string(mProperty);
|
||||
}
|
||||
|
||||
if (!icalstr) {
|
||||
if (icalerrno == ICAL_BADARG_ERROR) {
|
||||
str.Truncate();
|
||||
// Set string to null, because we don't have a value
|
||||
// (which is something different then an empty value)
|
||||
str.SetIsVoid(PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -89,7 +103,49 @@ calIcalProperty::GetStringValue(nsACString &str)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::SetStringValue(const nsACString &str)
|
||||
calIcalProperty::SetValue(const nsACString &str)
|
||||
{
|
||||
icalvalue_kind kind = icalproperty_kind_to_value_kind(icalproperty_isa(mProperty));
|
||||
if (kind == ICAL_TEXT_VALUE) {
|
||||
icalvalue *v = icalvalue_new_text(PromiseFlatCString(str).get());
|
||||
icalproperty_set_value(mProperty, v);
|
||||
} else if (kind == ICAL_X_VALUE) {
|
||||
icalvalue *v = icalvalue_new_x(PromiseFlatCString(str).get());
|
||||
icalproperty_set_value(mProperty, v);
|
||||
} else {
|
||||
icalproperty_set_value_from_string(mProperty,
|
||||
PromiseFlatCString(str).get(),
|
||||
icalvalue_kind_to_string(kind));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::GetValueAsIcalString(nsACString &str)
|
||||
{
|
||||
const char *icalstr = icalproperty_get_value_as_string(mProperty);
|
||||
if (!icalstr) {
|
||||
if (icalerrno == ICAL_BADARG_ERROR) {
|
||||
str.Truncate();
|
||||
// Set string to null, because we don't have a value
|
||||
// (which is something different then an empty value)
|
||||
str.SetIsVoid(PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Error getting string value: %d (%s)\n",
|
||||
icalerrno, icalerror_strerror(icalerrno));
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
str.Assign(icalstr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
calIcalProperty::SetValueAsIcalString(const nsACString &str)
|
||||
{
|
||||
const char *kindstr =
|
||||
icalvalue_kind_to_string(icalproperty_kind_to_value_kind(icalproperty_isa(mProperty)));
|
||||
|
@ -380,7 +436,7 @@ calIcalComponent::AddTimezoneReference(calIIcalComponent *aTimezone)
|
|||
}
|
||||
|
||||
nsCAutoString tzid;
|
||||
rv = tzidProp->GetStringValue(tzid);
|
||||
rv = tzidProp->GetValue(tzid);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// figure out if we already have this tzid
|
||||
|
|
|
@ -484,7 +484,7 @@ calItemBase.prototype = {
|
|||
|
||||
var gen = icalcomp.getFirstProperty("X-MOZILLA-GENERATION");
|
||||
if (gen)
|
||||
this.mGeneration = parseInt(gen.stringValue);
|
||||
this.mGeneration = parseInt(gen.value);
|
||||
|
||||
// find recurrence properties
|
||||
var rec = null;
|
||||
|
@ -521,7 +521,7 @@ calItemBase.prototype = {
|
|||
var triggerProp = alarmComp.getFirstProperty("TRIGGER");
|
||||
var duration = Components.classes["@mozilla.org/calendar/duration;1"]
|
||||
.createInstance(Components.interfaces.calIDuration);
|
||||
duration.icalString = triggerProp.stringValue;
|
||||
duration.icalString = triggerProp.valueAsIcalString;
|
||||
|
||||
if (duration.minutes) {
|
||||
this.setProperty("alarmLength", duration.minutes);
|
||||
|
@ -552,7 +552,7 @@ calItemBase.prototype = {
|
|||
prop = icalcomp.getNextProperty("ANY")) {
|
||||
if (!promoted[prop.propertyName]) {
|
||||
// XXX keep parameters around, sigh
|
||||
this.setProperty(prop.propertyName, prop.stringValue);
|
||||
this.setProperty(prop.propertyName, prop.value);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -579,7 +579,7 @@ calItemBase.prototype = {
|
|||
|
||||
if (this.mGeneration) {
|
||||
var genprop = icalProp("X-MOZILLA-GENERATION");
|
||||
genprop.stringValue = String(this.mGeneration);
|
||||
genprop.value = String(this.mGeneration);
|
||||
icalcomp.addProperty(genprop);
|
||||
}
|
||||
|
||||
|
@ -601,7 +601,7 @@ calItemBase.prototype = {
|
|||
duration[this.getProperty("alarmUnits")] = this.getProperty("alarmLength");
|
||||
|
||||
var triggerProp = icssvc.createIcalProperty("TRIGGER");
|
||||
triggerProp.stringValue = duration.icalString;
|
||||
triggerProp.valueAsIcalString = duration.icalString;
|
||||
|
||||
if (this.getProperty("alarmRelated") == "END")
|
||||
triggerProp.setParameter("RELATED", "END");
|
||||
|
@ -610,7 +610,7 @@ calItemBase.prototype = {
|
|||
|
||||
if (this.getProperty("alarmEmailAddress")) {
|
||||
var emailProp = icssvc.createIcalProperty("X-EMAILADDRESS");
|
||||
emailProp.stringValue = this.getProperty("alarmEmailAddress");
|
||||
emailProp.value = this.getProperty("alarmEmailAddress");
|
||||
alarmComp.addProperty(emailProp);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче