aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKelvin Jackson <kechpaja@comcast.net>2020-02-19 14:13:41 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2020-03-22 13:40:28 -0400
commit80b60d63cb751134e31955836e011a7dc593f4f8 (patch)
tree75b3cf03f0edc04bd3482df486ef3d627a18d968 /src
parent96c0790804f9c80803debc2e7b61d216ab66b3af (diff)
downloadcalcurse-80b60d63cb751134e31955836e011a7dc593f4f8.tar.gz
calcurse-80b60d63cb751134e31955836e011a7dc593f4f8.zip
Escape necessary characters in SUMMARY on export
Escape semicolons, commas, and backslashes when exporting a calendar item to iCal format. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
Diffstat (limited to 'src')
-rw-r--r--src/ical.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/src/ical.c b/src/ical.c
index 79b15de..2438351 100644
--- a/src/ical.c
+++ b/src/ical.c
@@ -72,6 +72,27 @@ static void ical_export_footer(FILE *);
static const char *ical_recur_type[RECUR_TYPES] =
{ "", "DAILY", "WEEKLY", "MONTHLY", "YEARLY" };
+/* Escape characters in field before printing */
+static void ical_format_line(FILE * stream, char * field, char * msg)
+{
+ char * p;
+
+ fputs(field, stream);
+ for (p = msg; *p; p++) {
+ switch (*p) {
+ case ',':
+ case ';':
+ case '\\':
+ fprintf(stream, "\\%c", *p);
+ break;
+ default:
+ fputc(*p, stream);
+ break;
+ }
+ }
+ fputc('\n', stream);
+}
+
/* iCal alarm notification. */
static void ical_export_valarm(FILE * stream)
{
@@ -130,7 +151,7 @@ static void ical_export_recur_events(FILE * stream, int export_uid)
}
}
- fprintf(stream, "SUMMARY:%s\n", rev->mesg);
+ ical_format_line(stream, "SUMMARY:", rev->mesg);
if (export_uid) {
char *hash = recur_event_hash(rev);
@@ -153,7 +174,7 @@ static void ical_export_events(FILE * stream, int export_uid)
date_sec2date_fmt(ev->day, ICALDATEFMT, ical_date);
fputs("BEGIN:VEVENT\n", stream);
fprintf(stream, "DTSTART;VALUE=DATE:%s\n", ical_date);
- fprintf(stream, "SUMMARY:%s\n", ev->mesg);
+ ical_format_line(stream, "SUMMARY:", ev->mesg);
if (export_uid) {
char *hash = event_hash(ev);
@@ -209,7 +230,7 @@ static void ical_export_recur_apoints(FILE * stream, int export_uid)
}
}
- fprintf(stream, "SUMMARY:%s\n", rapt->mesg);
+ ical_format_line(stream, "SUMMARY:", rapt->mesg);
if (rapt->state & APOINT_NOTIFY)
ical_export_valarm(stream);
@@ -244,7 +265,7 @@ static void ical_export_apoints(FILE * stream, int export_uid)
(apt->dur / MININSEC) % HOURINMIN,
apt->dur % MININSEC);
}
- fprintf(stream, "SUMMARY:%s\n", apt->mesg);
+ ical_format_line(stream, "SUMMARY:", apt->mesg);
if (apt->state & APOINT_NOTIFY)
ical_export_valarm(stream);
@@ -271,7 +292,7 @@ static void ical_export_todo(FILE * stream, int export_uid)
if (todo->completed)
fprintf(stream, "STATUS:COMPLETED\n");
fprintf(stream, "PRIORITY:%d\n", todo->id);
- fprintf(stream, "SUMMARY:%s\n", todo->mesg);
+ ical_format_line(stream, "SUMMARY:", todo->mesg);
if (export_uid) {
char *hash = todo_hash(todo);