summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gmail.com>2019-09-02 13:21:22 +0000
committerEmmanuele Bassi <ebassi@gmail.com>2019-09-02 13:21:22 +0000
commitf998e714a7936288b404cfc92cd00b786c7e64dd (patch)
tree617bd73f29467cfd38938c5c38c03c92bc44708c
parent33905dd9951345d3bdd3d0c28d266bad1a738376 (diff)
parent2ce0d7ab7c9ce5fab435008cf9637cadf07406fe (diff)
downloadglib-f998e714a7936288b404cfc92cd00b786c7e64dd.tar.gz
Merge branch 'backport-1017-iso8601-parsing-glib-2-60' into 'glib-2-60'
Backport !1017 “gdatetime: Avoid an assertion failure when parsing some ISO 8601 dates” to glib-2-60 See merge request GNOME/glib!1081
-rw-r--r--glib/gdatetime.c10
-rw-r--r--glib/tests/gdatetime.c3
2 files changed, 11 insertions, 2 deletions
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index 8abf45a87..7c94adf56 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -1353,8 +1353,14 @@ parse_iso8601_timezone (const gchar *text, gsize length, gssize *tz_offset)
tz = g_time_zone_new (text + i);
/* Double-check that the GTimeZone matches our interpretation of the timezone.
- * Failure would indicate a bug either here of in the GTimeZone code. */
- g_assert (g_time_zone_get_offset (tz, 0) == offset_sign * (offset_hours * 3600 + offset_minutes * 60));
+ * This can fail because our interpretation is less strict than (for example)
+ * parse_time() in gtimezone.c, which restricts the range of the parsed
+ * integers. */
+ if (g_time_zone_get_offset (tz, 0) != offset_sign * (offset_hours * 3600 + offset_minutes * 60))
+ {
+ g_time_zone_unref (tz);
+ return NULL;
+ }
return tz;
}
diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c
index 00e22181e..8178e2205 100644
--- a/glib/tests/gdatetime.c
+++ b/glib/tests/gdatetime.c
@@ -490,6 +490,9 @@ test_GDateTime_new_from_iso8601 (void)
dt = g_date_time_new_from_iso8601 ("not a date", NULL);
g_assert_null (dt);
+ dt = g_date_time_new_from_iso8601 (" +55", NULL);
+ g_assert_null (dt);
+
/* Check common case */
dt = g_date_time_new_from_iso8601 ("2016-08-24T22:10:42Z", NULL);
ASSERT_DATE (dt, 2016, 8, 24);