[grilo-plugins] lua-factory: Warn when dates are in an invalid format



commit cfbadd4278c77b1378288ddcd0a05863fd1dcac2
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Nov 1 19:16:58 2014 +0100

    lua-factory: Warn when dates are in an invalid format
    
    Instead of throwing g_date_time_unref() errors.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=739508

 src/lua-factory/grl-lua-library.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index c48a7a8..711e148 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -284,9 +284,15 @@ grl_util_build_media (lua_State *L,
         /* Non-fundamental types don't reduce to ints, so can't be
          * in the switch statement */
         if (type == G_TYPE_DATE_TIME) {
-          GDateTime *date = grl_date_time_from_iso8601 (lua_tostring (L, -1));
-          grl_data_set_boxed (GRL_DATA (media), key_id, date);
-          g_date_time_unref (date);
+          GDateTime *date;
+          const char *date_str = lua_tostring (L, -1);
+          date = grl_date_time_from_iso8601 (date_str);
+          if (date) {
+            grl_data_set_boxed (GRL_DATA (media), key_id, date);
+            g_date_time_unref (date);
+          } else {
+            GRL_WARNING ("'%s' is not a valid ISO-8601 date", date_str);
+          }
         } else if (type == G_TYPE_BYTE_ARRAY) {
            gsize size = luaL_len (L, -1);
            const guint8 *binary = (const guint8 *) lua_tostring (L, -1);


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