diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2014-08-09 21:10:03 +0100 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2014-08-09 21:28:28 +0100 |
commit | 18c16bfc9e517d44bf84449e58cc5b10bde07f09 (patch) | |
tree | 1c434bd182bee93e148f941ca5aabbf7539ca248 | |
parent | 30546923f89ce2b95cb6f6e97bf59317e5f69fda (diff) | |
download | libgdata-18c16bfc9e517d44bf84449e58cc5b10bde07f09.tar.gz |
core: Tweak generated ISO8601 dates to appease Google’s parsers
Even though the protocol documentation claims to accept RFC3339 dates,
the servers have recently started rejecting dates formatted as
‘2014-08-09T21:10:05Z’ which don’t include microseconds and specify the
timezone non-numerically.
Since the issue hasn’t been resolved at Google’s end, we need to hack
the date formats generated by libgdata to appease the servers,
completely undermining the point of having a defined protocol and RFC to
base the code on. Sigh.
Change gdata_parser_int64_to_iso8601() to produce dates in the format
‘YYYY-MM-DDTHH:MM:SS.000001+00:00’. This was previously used by the JSON
output generator, so perhaps the server breakage was introduced when
Google started rolling out the JSON APIs.
https://bugzilla.gnome.org/show_bug.cgi?id=732809
-rw-r--r-- | gdata/gdata-parser.c | 29 | ||||
-rw-r--r-- | gdata/tests/calendar.c | 20 | ||||
-rw-r--r-- | gdata/tests/general.c | 32 | ||||
-rw-r--r-- | gdata/tests/youtube.c | 16 |
4 files changed, 51 insertions, 46 deletions
diff --git a/gdata/gdata-parser.c b/gdata/gdata-parser.c index 9d249621..4409de5c 100644 --- a/gdata/gdata-parser.c +++ b/gdata/gdata-parser.c @@ -241,23 +241,22 @@ gchar * gdata_parser_int64_to_iso8601 (gint64 _time) { GTimeVal time_val; - - time_val.tv_sec = _time; - time_val.tv_usec = 0; - - return g_time_val_to_iso8601 (&time_val); -} - -/* FIXME: Work around for Google's incorrect ISO 8601 implementation. */ -gchar * -gdata_parser_int64_to_json_iso8601 (gint64 _time) -{ gchar *iso8601; gchar **date_time_components; gchar *retval; - iso8601 = gdata_parser_int64_to_iso8601 (_time); + time_val.tv_sec = _time; + time_val.tv_usec = 0; + + iso8601 = g_time_val_to_iso8601 (&time_val); + /* FIXME: Work around for Google's incorrect ISO 8601 implementation. + * They appear to not like dates in the format ‘2014-08-09T21:07:05Z’ + * which specify a timezone using ‘Z’ and no microseconds. + * + * See: https://bugzilla.gnome.org/show_bug.cgi?id=732809 + * https://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3595 + * http://stackoverflow.com/a/17630320/2931197 */ date_time_components = g_strsplit (iso8601, "Z", 2); retval = g_strjoinv (".000001+00:00", date_time_components); g_strfreev (date_time_components); @@ -267,6 +266,12 @@ gdata_parser_int64_to_json_iso8601 (gint64 _time) return retval; } +gchar * +gdata_parser_int64_to_json_iso8601 (gint64 _time) +{ + return gdata_parser_int64_to_iso8601 (_time); +} + gboolean gdata_parser_int64_from_iso8601 (const gchar *date, gint64 *_time) { diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c index c54ddda0..bb1d6090 100644 --- a/gdata/tests/calendar.c +++ b/gdata/tests/calendar.c @@ -620,7 +620,7 @@ test_event_xml (void) "<gCal:guestsCanInviteOthers value='false'/>" "<gCal:guestsCanSeeGuests value='false'/>" "<gCal:anyoneCanAddSelf value='false'/>" - "<gd:when startTime='2009-04-17T15:00:00Z' endTime='2009-04-17T17:00:00Z'/>" + "<gd:when startTime='2009-04-17T15:00:00.000001+00:00' endTime='2009-04-17T17:00:00.000001+00:00'/>" "<gd:who email='john.smith@example.com' " "rel='http://schemas.google.com/g/2005#event.organizer' " "valueString='John Smith\342\200\275'/>" @@ -706,7 +706,7 @@ test_event_xml_dates (void) "<gCal:guestsCanSeeGuests value='false'/>" "<gCal:anyoneCanAddSelf value='false'/>" "<gd:when startTime='2009-04-17'/>" - "<gd:when startTime='2009-04-17T15:00:00Z'/>" + "<gd:when startTime='2009-04-17T15:00:00.000001+00:00'/>" "<gd:when startTime='2009-04-27' endTime='2009-05-06'/>" "</entry>"); @@ -934,25 +934,25 @@ test_query_uri (void) /* Check the built query URI with a normal feed URI */ query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), "http://example.com"); - g_assert_cmpstr (query_uri, ==, "http://example.com?q=q&futureevents=true&orderby=starttime&recurrence-expansion-start=2009-04-17T15:00:00Z" - "&recurrence-expansion-end=2010-04-17T15:00:00Z&singleevents=true&sortorder=descending" - "&start-min=2009-04-17T15:00:00Z&start-max=2010-04-17T15:00:00Z&ctz=America%2FLos_Angeles&max-attendees=15" + g_assert_cmpstr (query_uri, ==, "http://example.com?q=q&futureevents=true&orderby=starttime&recurrence-expansion-start=2009-04-17T15:00:00.000001+00:00" + "&recurrence-expansion-end=2010-04-17T15:00:00.000001+00:00&singleevents=true&sortorder=descending" + "&start-min=2009-04-17T15:00:00.000001+00:00&start-max=2010-04-17T15:00:00.000001+00:00&ctz=America%2FLos_Angeles&max-attendees=15" "&showdeleted=true"); g_free (query_uri); /* …with a feed URI with a trailing slash */ query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), "http://example.com/"); - g_assert_cmpstr (query_uri, ==, "http://example.com/?q=q&futureevents=true&orderby=starttime&recurrence-expansion-start=2009-04-17T15:00:00Z" - "&recurrence-expansion-end=2010-04-17T15:00:00Z&singleevents=true&sortorder=descending" - "&start-min=2009-04-17T15:00:00Z&start-max=2010-04-17T15:00:00Z&ctz=America%2FLos_Angeles&max-attendees=15" + g_assert_cmpstr (query_uri, ==, "http://example.com/?q=q&futureevents=true&orderby=starttime&recurrence-expansion-start=2009-04-17T15:00:00.000001+00:00" + "&recurrence-expansion-end=2010-04-17T15:00:00.000001+00:00&singleevents=true&sortorder=descending" + "&start-min=2009-04-17T15:00:00.000001+00:00&start-max=2010-04-17T15:00:00.000001+00:00&ctz=America%2FLos_Angeles&max-attendees=15" "&showdeleted=true"); g_free (query_uri); /* …with a feed URI with pre-existing arguments */ query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), "http://example.com/bar/?test=test&this=that"); g_assert_cmpstr (query_uri, ==, "http://example.com/bar/?test=test&this=that&q=q&futureevents=true&orderby=starttime" - "&recurrence-expansion-start=2009-04-17T15:00:00Z&recurrence-expansion-end=2010-04-17T15:00:00Z" - "&singleevents=true&sortorder=descending&start-min=2009-04-17T15:00:00Z&start-max=2010-04-17T15:00:00Z" + "&recurrence-expansion-start=2009-04-17T15:00:00.000001+00:00&recurrence-expansion-end=2010-04-17T15:00:00.000001+00:00" + "&singleevents=true&sortorder=descending&start-min=2009-04-17T15:00:00.000001+00:00&start-max=2010-04-17T15:00:00.000001+00:00" "&ctz=America%2FLos_Angeles&max-attendees=15&showdeleted=true"); g_free (query_uri); diff --git a/gdata/tests/general.c b/gdata/tests/general.c index fbb2c849..f920727d 100644 --- a/gdata/tests/general.c +++ b/gdata/tests/general.c @@ -528,8 +528,8 @@ test_entry_parse_xml (void) "<?xml version='1.0' encoding='UTF-8'?>" "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:ns='http://example.com/'>" "<title type='text'>Testing unhandled XML</title>" - "<updated>2009-01-25T14:07:37Z</updated>" - "<published>2009-01-23T14:06:37Z</published>" + "<updated>2009-01-25T14:07:37.000001+00:00</updated>" + "<published>2009-01-23T14:06:37.000001+00:00</published>" "<content type='text'>Here we test unhandled XML elements.</content>" "<foobar>Test!</foobar>" "<barfoo shizzle=\"zing\"/>" @@ -569,8 +569,8 @@ test_entry_parse_xml_kind_category (void) "<?xml version='1.0' encoding='UTF-8'?>" "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>" "<title type='text'>Testing kind categories</title>" - "<updated>2009-01-25T14:07:37Z</updated>" - "<published>2009-01-23T14:06:37Z</published>" + "<updated>2009-01-25T14:07:37.000001+00:00</updated>" + "<published>2009-01-23T14:06:37.000001+00:00</published>" "<content type='text'>Here we test kind categories.</content>" "<category term='http://schemas.google.com/docs/2007#file' " "scheme='http://schemas.google.com/g/2005#kind' " @@ -760,8 +760,8 @@ test_entry_escaping (void) "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>" "<title type='text'>Escaped content & stuff</title>" "<id>http://foo.com/?foo&bar</id>" - "<updated>2010-12-10T17:21:24Z</updated>" - "<published>2010-12-10T17:21:24Z</published>" + "<updated>2010-12-10T17:21:24.000001+00:00</updated>" + "<published>2010-12-10T17:21:24.000001+00:00</published>" "<summary type='text'>Summary & stuff</summary>" "<rights>Free & open source</rights>" "<content type='text'>Content & things.</content>" @@ -1106,7 +1106,7 @@ test_feed_escaping (void) "<feed xmlns='http://www.w3.org/2005/Atom'>" "<title type='text'>Test feed & stuff.</title>" "<id>http://foo.com?foo&bar</id>" - "<updated>2010-12-10T17:49:15Z</updated>" + "<updated>2010-12-10T17:49:15.000001+00:00</updated>" "</feed>"); g_object_unref (feed); } @@ -1157,28 +1157,28 @@ test_query_dates (void) /* updated-min */ gdata_query_set_updated_min (query, 1373280114); /* 2013-07-08T10:41:54Z */ query_uri = gdata_query_get_query_uri (query, "http://example.com"); - g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&updated-min=2013-07-08T10:41:54Z"); + g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&updated-min=2013-07-08T10:41:54.000001+00:00"); g_free (query_uri); gdata_query_set_updated_min (query, -1); /* updated-max */ gdata_query_set_updated_max (query, 1373280114); /* 2013-07-08T10:41:54Z */ query_uri = gdata_query_get_query_uri (query, "http://example.com"); - g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&updated-max=2013-07-08T10:41:54Z"); + g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&updated-max=2013-07-08T10:41:54.000001+00:00"); g_free (query_uri); gdata_query_set_updated_max (query, -1); /* published-min */ gdata_query_set_published_min (query, 1373280114); /* 2013-07-08T10:41:54Z */ query_uri = gdata_query_get_query_uri (query, "http://example.com"); - g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&published-min=2013-07-08T10:41:54Z"); + g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&published-min=2013-07-08T10:41:54.000001+00:00"); g_free (query_uri); gdata_query_set_published_min (query, -1); /* published-max */ gdata_query_set_published_max (query, 1373280114); /* 2013-07-08T10:41:54Z */ query_uri = gdata_query_get_query_uri (query, "http://example.com"); - g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&published-max=2013-07-08T10:41:54Z"); + g_assert_cmpstr (query_uri, ==, "http://example.com?q=baz&published-max=2013-07-08T10:41:54.000001+00:00"); g_free (query_uri); gdata_query_set_published_max (query, -1); @@ -3071,7 +3071,7 @@ test_gd_reminder (void) gdata_test_assert_xml (reminder, "<?xml version='1.0' encoding='UTF-8'?>" "<gd:reminder xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' " - "absoluteTime='2005-06-07T00:55:00Z' method='alert'/>"); + "absoluteTime='2005-06-07T00:55:00.000001+00:00' method='alert'/>"); g_object_unref (reminder); } @@ -3162,8 +3162,8 @@ test_gd_when (void) /* Check the outputted XML is the same */ gdata_test_assert_xml (when, "<?xml version='1.0' encoding='UTF-8'?>" - "<gd:when xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' startTime='2005-06-07T01:00:00Z' " - "endTime='2005-06-07T02:00:00Z'/>"); + "<gd:when xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' startTime='2005-06-07T01:00:00.000001+00:00' " + "endTime='2005-06-07T02:00:00.000001+00:00'/>"); g_object_unref (when); /* Now parse a time with different information */ @@ -3202,7 +3202,7 @@ test_gd_when (void) "<gd:when xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' startTime='2005-06-06' " "endTime='2005-06-08' valueString='This weekend'>" "<gd:reminder minutes='15'/>" - "<gd:reminder absoluteTime='2005-06-06T00:00:00Z' method='alert'/>" + "<gd:reminder absoluteTime='2005-06-06T00:00:00.000001+00:00' method='alert'/>" "<foobar/>" "</gd:when>"); g_object_unref (when); @@ -3222,7 +3222,7 @@ test_gd_when_escaping (void) gdata_test_assert_xml (when, "<?xml version='1.0' encoding='UTF-8'?>" "<gd:when xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' " - "startTime='2005-06-07T01:00:00Z' valueString='Value string & stuff!'/>"); + "startTime='2005-06-07T01:00:00.000001+00:00' valueString='Value string & stuff!'/>"); g_object_unref (when); } diff --git a/gdata/tests/youtube.c b/gdata/tests/youtube.c index 1195bc3a..a1e070aa 100644 --- a/gdata/tests/youtube.c +++ b/gdata/tests/youtube.c @@ -967,8 +967,8 @@ test_parsing_yt_recorded (void) "gd:etag='W/\"CEMFSX47eCp7ImA9WxVUGEw.\"'>" "<title type='text'>Judas Priest - Painkiller</title>" "<id>tag:youtube.com,2008:video:JAagedeKdcQ</id>" - "<updated>2009-03-23T12:46:58Z</updated>" - "<published>2006-05-16T14:06:37Z</published>" + "<updated>2009-03-23T12:46:58.000001+00:00</updated>" + "<published>2006-05-16T14:06:37.000001+00:00</published>" "<category term='http://gdata.youtube.com/schemas/2007#video' scheme='http://schemas.google.com/g/2005#kind'/>" "<link href='http://www.youtube.com/watch?v=JAagedeKdcQ' rel='http://www.iana.org/assignments/relation/alternate' type='text/html'/>" "<link href='http://gdata.youtube.com/feeds/api/videos/JAagedeKdcQ?client=ytapi-google-jsdemo' rel='http://www.iana.org/assignments/relation/self' type='application/atom+xml'/>" @@ -1055,8 +1055,8 @@ test_parsing_yt_access_control (void) "gd:etag='W/\"CEMFSX47eCp7ImA9WxVUGEw.\"'>" "<title type='text'>Judas Priest - Painkiller</title>" "<id>tag:youtube.com,2008:video:JAagedeKdcQ</id>" - "<updated>2009-03-23T12:46:58Z</updated>" - "<published>2006-05-16T14:06:37Z</published>" + "<updated>2009-03-23T12:46:58.000001+00:00</updated>" + "<published>2006-05-16T14:06:37.000001+00:00</published>" "<category term='http://gdata.youtube.com/schemas/2007#video' scheme='http://schemas.google.com/g/2005#kind'/>" "<link href='http://www.youtube.com/watch?v=JAagedeKdcQ' rel='http://www.iana.org/assignments/relation/alternate' type='text/html'/>" "<link href='http://gdata.youtube.com/feeds/api/videos/JAagedeKdcQ?client=ytapi-google-jsdemo' rel='http://www.iana.org/assignments/relation/self' type='application/atom+xml'/>" @@ -1255,8 +1255,8 @@ test_parsing_georss_where (void) "xmlns:gml='http://www.opengis.net/gml'>" "<title type='text'>Some video somewhere</title>" "<id>tag:youtube.com,2008:video:JAagedeKdcQ</id>" - "<updated>2009-03-23T12:46:58Z</updated>" - "<published>2006-05-16T14:06:37Z</published>" + "<updated>2009-03-23T12:46:58.000001+00:00</updated>" + "<published>2006-05-16T14:06:37.000001+00:00</published>" "<category term='http://gdata.youtube.com/schemas/2007#video' scheme='http://schemas.google.com/g/2005#kind'/>" "<link href='http://www.youtube.com/watch?v=JAagedeKdcQ' rel='http://www.iana.org/assignments/relation/alternate' type='text/html'/>" "<link href='http://gdata.youtube.com/feeds/api/videos/JAagedeKdcQ?client=ytapi-google-jsdemo' rel='http://www.iana.org/assignments/relation/self' type='application/atom+xml'/>" @@ -1295,8 +1295,8 @@ test_parsing_georss_where (void) "xmlns:gml='http://www.opengis.net/gml'>" "<title type='text'>Some video somewhere</title>" "<id>tag:youtube.com,2008:video:JAagedeKdcQ</id>" - "<updated>2009-03-23T12:46:58Z</updated>" - "<published>2006-05-16T14:06:37Z</published>" + "<updated>2009-03-23T12:46:58.000001+00:00</updated>" + "<published>2006-05-16T14:06:37.000001+00:00</published>" "<category term='http://gdata.youtube.com/schemas/2007#video' scheme='http://schemas.google.com/g/2005#kind'/>" "<link href='http://www.youtube.com/watch?v=JAagedeKdcQ' rel='http://www.iana.org/assignments/relation/alternate' type='text/html'/>" "<link href='http://gdata.youtube.com/feeds/api/videos/JAagedeKdcQ?client=ytapi-google-jsdemo' rel='http://www.iana.org/assignments/relation/self' type='application/atom+xml'/>" |