[tepl] Encoding: check that a default candidate has a known charset



commit e9082259397085e29a87d6872818bb1aba71782a
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Oct 22 16:19:19 2017 +0200

    Encoding: check that a default candidate has a known charset

 tepl/tepl-encoding.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/tepl/tepl-encoding.c b/tepl/tepl-encoding.c
index 4c2d545..16d390d 100644
--- a/tepl/tepl-encoding.c
+++ b/tepl/tepl-encoding.c
@@ -586,11 +586,14 @@ _tepl_encoding_remove_duplicates (GSList                 *list,
 
 /* Returns: (transfer full) (element-type TeplEncoding). */
 static GSList *
-strv_to_list (const gchar * const *enc_str)
+default_candidates_strv_to_list (const gchar * const *enc_str)
 {
+       GSList *all_encodings;
        GSList *list = NULL;
        gchar **p;
 
+       all_encodings = tepl_encoding_get_all ();
+
        for (p = (gchar **)enc_str; p != NULL && *p != NULL; p++)
        {
                const gchar *charset = *p;
@@ -608,13 +611,28 @@ strv_to_list (const gchar * const *enc_str)
                if (present_in_list (list, enc))
                {
                        tepl_encoding_free (enc);
+                       continue;
                }
-               else
+
+               /* If the translator has not translated correctly the list of
+                * default candidate encodings, ensure that it won't trigger a
+                * file loading error.
+                */
+               if (!present_in_list (all_encodings, enc))
                {
-                       list = g_slist_prepend (list, enc);
+                       g_warning ("TeplEncoding: unknown charset '%s', "
+                                  "ignoring it for the default candidates.",
+                                  charset);
+
+                       tepl_encoding_free (enc);
+                       continue;
                }
+
+               list = g_slist_prepend (list, enc);
        }
 
+       g_slist_free_full (all_encodings, (GDestroyNotify)tepl_encoding_free);
+
        return g_slist_reverse (list);
 }
 
@@ -695,7 +713,7 @@ tepl_encoding_get_default_candidates (void)
        g_variant_ref_sink (encodings_variant);
 
        encodings_strv = g_variant_get_strv (encodings_variant, NULL);
-       encodings_list = strv_to_list (encodings_strv);
+       encodings_list = default_candidates_strv_to_list (encodings_strv);
        g_free ((gpointer) encodings_strv);
 
        /* Ensure that UTF-8 and CURRENT are present. */


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