summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2007-12-19 17:28:38 +0000
committerEmmanuele Bassi <ebassi@src.gnome.org>2007-12-19 17:28:38 +0000
commita979c0d5a2124cbfe5114c5e3f1e7eefc0e230fd (patch)
treef52f24cd0c63af6985aa75ab9eeb96de05825df4
parent28d1c8e0ad86253c84de1ee948a338eec98ae701 (diff)
downloadglib-a979c0d5a2124cbfe5114c5e3f1e7eefc0e230fd.tar.gz
Fix the date validation check. (#503029)
2007-12-19 Emmanuele Bassi <ebassi@gnome.org> * glib/gtimer.c (g_time_val_from_iso8601): Fix the date validation check. (#503029) * tests/testglib.c (various_string_tests): Add an invalid date for testing the above fix. svn path=/trunk/; revision=6160
-rw-r--r--ChangeLog8
-rw-r--r--glib/gtimer.c4
-rw-r--r--tests/testglib.c2
3 files changed, 13 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 95644034e..520c90c8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-12-19 Emmanuele Bassi <ebassi@gnome.org>
+
+ * glib/gtimer.c (g_time_val_from_iso8601): Fix the date validation
+ check. (#503029)
+
+ * tests/testglib.c (various_string_tests): Add an invalid date
+ for testing the above fix.
+
2007-12-19 Alexander Larsson <alexl@redhat.com>
* glib/gfileutils.[ch]:
diff --git a/glib/gtimer.c b/glib/gtimer.c
index 3b0b308c9..b625ddb54 100644
--- a/glib/gtimer.c
+++ b/glib/gtimer.c
@@ -312,9 +312,11 @@ g_time_val_from_iso8601 (const gchar *iso_date,
* have an ISO 8601 date */
while (g_ascii_isspace (*iso_date))
iso_date++;
+
if (*iso_date == '\0')
return FALSE;
- if (!g_ascii_isdigit (*iso_date) || iso_date != '-' || *iso_date != '+')
+
+ if (!g_ascii_isdigit (*iso_date) && *iso_date != '-' && *iso_date != '+')
return FALSE;
val = strtoul (iso_date, (char **)&iso_date, 10);
diff --git a/tests/testglib.c b/tests/testglib.c
index 9838dc863..6275e733c 100644
--- a/tests/testglib.c
+++ b/tests/testglib.c
@@ -1382,6 +1382,7 @@ various_string_tests (void)
g_free (tmp_string);
g_free (string);
+#define REF_INVALID "Wed Dec 19 17:20:20 GMT 2007"
#define REF_SEC_UTC 320063760
#define REF_STR_UTC "1980-02-22T10:36:00Z"
#define REF_STR_CEST "1980-02-22T12:36:00+02:00"
@@ -1391,6 +1392,7 @@ various_string_tests (void)
g_print ("checking g_time_val_from_iso8601...\n");
ref_date.tv_sec = REF_SEC_UTC;
ref_date.tv_usec = 0;
+ g_assert (g_time_val_from_iso8601 (REF_INVALID, &date) == FALSE);
g_assert (g_time_val_from_iso8601 (REF_STR_UTC, &date) != FALSE);
if (g_test_verbose())
g_print ("\t=> UTC stamp = %ld (should be: %ld) (%ld off)\n", date.tv_sec, ref_date.tv_sec, date.tv_sec - ref_date.tv_sec);