[tracker/wip/carlosg/datetime-fixes: 2/5] libtracker-data: Check better for errors in datetime parsing




commit 5782cf7415370eaf626df772fc6aa41df989ee2f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Oct 10 13:29:12 2020 +0200

    libtracker-data: Check better for errors in datetime parsing
    
    When parsing iso8601 strings, we may end up with a legit negative
    timestamp. Checking for it being negative makes us fail (with no
    error!) for dates before the epoch, check the error instead.
    
    Fixes parsing issues with queries with ancient datetimes like:
    select ("0100-12-31T21:00:00-03:00"^^xsd:dateTime as ?date) {}

 src/libtracker-data/tracker-sparql.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql.c b/src/libtracker-data/tracker-sparql.c
index cf023cbb8..be046da2a 100644
--- a/src/libtracker-data/tracker-sparql.c
+++ b/src/libtracker-data/tracker-sparql.c
@@ -9371,25 +9371,29 @@ prepare_query (TrackerSparql         *sparql,
                                return NULL;
                        }
                } else if (prop_type == TRACKER_PROPERTY_TYPE_DATE) {
+                       GError *inner_error = NULL;
                        gchar *full_str;
                        gdouble datetime;
 
                        full_str = g_strdup_printf ("%sT00:00:00Z", binding->literal);
-                       datetime = tracker_string_to_date (full_str, NULL, error);
+                       datetime = tracker_string_to_date (full_str, NULL, &inner_error);
                        g_free (full_str);
 
-                       if (datetime < 0) {
+                       if (inner_error) {
+                               g_propagate_error (error, inner_error);
                                g_object_unref (stmt);
                                return NULL;
                        }
 
                        tracker_db_statement_bind_int (stmt, i, (int) datetime);
                } else if (prop_type == TRACKER_PROPERTY_TYPE_DATETIME) {
+                       GError *inner_error = NULL;
                        gdouble datetime;
                        gint offset = 0;
 
-                       datetime = tracker_string_to_date (binding->literal, offset, error);
-                       if (datetime < 0) {
+                       datetime = tracker_string_to_date (binding->literal, offset, &inner_error);
+                       if (inner_error) {
+                               g_propagate_error (error, inner_error);
                                g_object_unref (stmt);
                                return NULL;
                        }


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