[evolution-data-server/gnome-3-28] Bug 796116 - [webcal] Skip UTF-8 marker when parsing iCalendar string
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/gnome-3-28] Bug 796116 - [webcal] Skip UTF-8 marker when parsing iCalendar string
- Date: Mon, 21 May 2018 16:36:30 +0000 (UTC)
commit 8d53a17adb27a7087e763c6f1226489c89c219b5
Author: Milan Crha <mcrha redhat com>
Date: Mon May 21 18:37:00 2018 +0200
Bug 796116 - [webcal] Skip UTF-8 marker when parsing iCalendar string
src/calendar/backends/http/e-cal-backend-http.c | 8 +++-
src/calendar/libecal/e-cal-util.c | 54 +++++++++++++++++++---
2 files changed, 53 insertions(+), 9 deletions(-)
---
diff --git a/src/calendar/backends/http/e-cal-backend-http.c b/src/calendar/backends/http/e-cal-backend-http.c
index 4f86c5c..cbeb2d8 100644
--- a/src/calendar/backends/http/e-cal-backend-http.c
+++ b/src/calendar/backends/http/e-cal-backend-http.c
@@ -341,7 +341,13 @@ ecb_http_get_changes_sync (ECalMetaBackend *meta_backend,
return FALSE;
}
- maincomp = icalparser_parse_string (icalstring);
+ /* Skip the UTF-8 marker at the beginning of the string */
+ if (((guchar) icalstring[0]) == 0xEF &&
+ ((guchar) icalstring[1]) == 0xBB &&
+ ((guchar) icalstring[2]) == 0xBF)
+ maincomp = icalparser_parse_string (icalstring + 3);
+ else
+ maincomp = icalparser_parse_string (icalstring);
g_free (icalstring);
diff --git a/src/calendar/libecal/e-cal-util.c b/src/calendar/libecal/e-cal-util.c
index b257c49..09749dd 100644
--- a/src/calendar/libecal/e-cal-util.c
+++ b/src/calendar/libecal/e-cal-util.c
@@ -207,12 +207,48 @@ e_cal_util_parse_ics_string (const gchar *string)
return icalcomp;
}
+struct ics_file {
+ FILE *file;
+ gboolean bof;
+};
+
static gchar *
get_line_fn (gchar *buf,
- gsize size,
- gpointer file)
+ gsize size,
+ gpointer user_data)
{
- return fgets (buf, size, file);
+ struct ics_file *fl = user_data;
+
+ /* Skip the UTF-8 marker at the beginning of the file */
+ if (fl->bof) {
+ gchar *orig_buf = buf;
+ gchar tmp[4];
+
+ fl->bof = FALSE;
+
+ if (fread (tmp, sizeof (gchar), 3, fl->file) != 3 || feof (fl->file))
+ return NULL;
+
+ if (((guchar) tmp[0]) != 0xEF ||
+ ((guchar) tmp[1]) != 0xBB ||
+ ((guchar) tmp[2]) != 0xBF) {
+ if (size <= 3)
+ return NULL;
+
+ buf[0] = tmp[0];
+ buf[1] = tmp[1];
+ buf[2] = tmp[2];
+ buf += 3;
+ size -= 3;
+ }
+
+ if (!fgets (buf, size, fl->file))
+ return NULL;
+
+ return orig_buf;
+ }
+
+ return fgets (buf, size, fl->file);
}
/**
@@ -230,18 +266,20 @@ e_cal_util_parse_ics_file (const gchar *filename)
{
icalparser *parser;
icalcomponent *icalcomp;
- FILE *file;
+ struct ics_file fl;
- file = g_fopen (filename, "rb");
- if (!file)
+ fl.file = g_fopen (filename, "rb");
+ if (!fl.file)
return NULL;
+ fl.bof = TRUE;
+
parser = icalparser_new ();
- icalparser_set_gen_data (parser, file);
+ icalparser_set_gen_data (parser, &fl);
icalcomp = icalparser_parse (parser, get_line_fn);
icalparser_free (parser);
- fclose (file);
+ fclose (fl.file);
return icalcomp;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]