[tracker-miners/sam/no-year-zero] extract: Avoid creating invalid ISO date strings




commit c0de3da7fdfa37bca4a32925d29ca03c1f767df2
Author: Sam Thursfield <sam afuera me uk>
Date:   Thu Jun 17 14:28:57 2021 +0200

    extract: Avoid creating invalid ISO date strings
    
    Fixes https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/175

 src/libtracker-extract/tracker-utils.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-extract/tracker-utils.c b/src/libtracker-extract/tracker-utils.c
index 4738775b3..c27cccfc1 100644
--- a/src/libtracker-extract/tracker-utils.c
+++ b/src/libtracker-extract/tracker-utils.c
@@ -511,7 +511,7 @@ parse_month (const gchar *month)
  * @date_string: the date in a string pointer
  *
  * This function uses a number of methods to try and guess the date
- * held in @date_string. The @date_string must be at least 5
+ * held in @date_string. The @date_string must be at least 4
  * characters in length or longer for any guessing to be attempted.
  * Some of the string formats guessed include:
  *
@@ -555,6 +555,11 @@ tracker_date_guess (const gchar *date_string)
         */
        if (len == 4) {
                if (is_int (date_string)) {
+                       if (atoi (date_string) == 0) {
+                               /* Avoid producing an invalid ISO date '0000-01-01T00:00:00Z' */
+                               return NULL;
+                       }
+
                        buf[0] = date_string[0];
                        buf[1] = date_string[1];
                        buf[2] = date_string[2];


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