[gnome-calendar/gnome-3-16] date-selector: fix crash on some locales



commit b3d3efc396a1cde857f902fda220b8c6ca045a81
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Tue Jun 2 23:06:49 2015 -0400

    date-selector: fix crash on some locales
    
    As stated on the bug below Calendar crashes in some locales because of the
    parsing of the string representing the date. Since parsing this string can be
    very tricky, we decided to make a simple translatable string with the format it
    is needed and th translators can set the proper order according to his locale.
    
    The translatable string goes as "%d/%m/%y" being %d the representation of the
    day, %m the representation of the month and, %y, the year. The translators
    should place it in the correct order for its locale, for instance en_US, should
    place it: "%m/%d/%y"
    
    The validation of the translated string is lacking some strength. It could use
    some improving.
    
    Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1226823

 src/gcal-date-selector.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/src/gcal-date-selector.c b/src/gcal-date-selector.c
index 1e90224..7875157 100644
--- a/src/gcal-date-selector.c
+++ b/src/gcal-date-selector.c
@@ -233,14 +233,26 @@ gcal_date_selector_init (GcalDateSelector *self)
   priv->month = 1;
   priv->year = 1970;
 
-  priv->mask = nl_langinfo (D_FMT);
+  /* This string represents day/month/year order for each of the differents
+   * languages. It could possibly be default value, %m/%d/%y placing the month
+   * before, or any ordering according to the translators environment */
+  priv->mask = _("%d/%m/%y");
 
   /**
-   * Select the day, month and year indexes. This will
+   * Translators: Select the day, month and year indexes. This will
    * be used later on to map the date entries to the
-   * corresponding indexes.
+   * corresponding indexes. I've should add more validations here.
    */
   max = strlen (priv->mask);
+  if (max != 6)
+    {
+      /* I'll assume an error and bail out with the default values */
+      priv->day_pos = 0;
+      priv->month_pos = 1;
+      priv->year_pos = 2;
+      return;
+    }
+
   d_index = 0;
 
   for (i = 0; i < max; i++)


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