[libgdata] calendar: Fix parsing of organizers without e-mail addresses



commit c658bb404b435fb054a86dbd5a060184d5fd6ba5
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sat Jan 28 01:00:01 2017 +0000

    calendar: Fix parsing of organizers without e-mail addresses
    
    It turns out the e-mail address for an organizer is optional.
    
    https://developers.google.com/google-apps/calendar/v3/reference/events#organizer.email
    
    Add a test.

 gdata/services/calendar/gdata-calendar-event.c |   18 +++----------
 gdata/tests/calendar.c                         |   32 ++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/gdata/services/calendar/gdata-calendar-event.c b/gdata/services/calendar/gdata-calendar-event.c
index 8ed3ec7..b952a52 100644
--- a/gdata/services/calendar/gdata-calendar-event.c
+++ b/gdata/services/calendar/gdata-calendar-event.c
@@ -943,20 +943,10 @@ parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GEr
        } else if (g_strcmp0 (json_reader_get_member_name (reader), "organizer") == 0) {
                const GError *child_error = NULL;
 
-               /* This actually gives the parent calendar. */
-               json_reader_read_member (reader, "email");
-               child_error = json_reader_get_error (reader);
-               if (child_error != NULL) {
-                       gdata_parser_error_from_json_error (reader,
-                                                           child_error,
-                                                           error);
-                       json_reader_end_member (reader);
-                       return FALSE;
-               }
-
-               g_free (priv->organiser_email);
-               priv->organiser_email = g_strdup (json_reader_get_string_value (reader));
-
+               /* This actually gives the parent calendar. Optional. */
+               g_clear_pointer (&priv->organiser_email, g_free);
+               if (json_reader_read_member (reader, "email"))
+                       priv->organiser_email = g_strdup (json_reader_get_string_value (reader));
                json_reader_end_member (reader);
 
                return TRUE;
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index 03f5194..6d5e0de 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -746,6 +746,37 @@ test_event_json_dates (void)
 }
 
 static void
+test_event_json_organizer (void)
+{
+       GDataCalendarEvent *event;
+       GError *error = NULL;
+
+       event = GDATA_CALENDAR_EVENT (gdata_parsable_new_from_json (GDATA_TYPE_CALENDAR_EVENT, "{"
+               "'kind': 'calendar#event',"
+               "'id': 'some-id',"
+               "'created': '2013-12-22T18:00:00.000Z',"
+               "'summary': 'FOSDEM GNOME Beer Event',"
+               "'organizer': {"
+                       "'id': 'another-id',"
+                       "'displayName': 'Guillaume Desmottes'"
+               "},"
+               "'attendees': ["
+                       "{"
+                               "'id': 'another-id',"
+                               "'displayName': 'Guillaume Desmottes',"
+                               "'organizer': true,"
+                               "'responseStatus': 'accepted'"
+                       "}"
+               "]"
+       "}", -1, &error));
+       g_assert_no_error (error);
+       g_assert (GDATA_IS_ENTRY (event));
+       g_clear_error (&error);
+
+       g_object_unref (event);
+}
+
+static void
 test_event_json_recurrence (void)
 {
        GDataCalendarEvent *event;
@@ -1440,6 +1471,7 @@ main (int argc, char *argv[])
 
        g_test_add_func ("/calendar/event/json", test_event_json);
        g_test_add_func ("/calendar/event/json/dates", test_event_json_dates);
+       g_test_add_func ("/calendar/event/json/organizer", test_event_json_organizer);
        g_test_add_func ("/calendar/event/json/recurrence", test_event_json_recurrence);
        g_test_add_func ("/calendar/event/escaping", test_event_escaping);
        g_test_add_func ("/calendar/event/parser/minimal",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]