[gnome-text-editor] enchant: work around possibly corrupted extra-word-chars



commit 9b654137cb8f86c55a1b834a0e55049c18806c2a
Author: Christian Hergert <chergert redhat com>
Date:   Thu Aug 5 13:36:38 2021 -0700

    enchant: work around possibly corrupted extra-word-chars
    
    Fedora seems to be a bit broken in this regard, so just truncate at the
    end of the valid UTF-8.

 src/enchant/editor-enchant-spell-language.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
---
diff --git a/src/enchant/editor-enchant-spell-language.c b/src/enchant/editor-enchant-spell-language.c
index 0480c82..1717cbb 100644
--- a/src/enchant/editor-enchant-spell-language.c
+++ b/src/enchant/editor-enchant-spell-language.c
@@ -29,6 +29,7 @@ struct _EditorEnchantSpellLanguage
   EditorSpellLanguage parent_instance;
   PangoLanguage *language;
   EnchantDict *native;
+  char *extra_word_chars;
 };
 
 G_DEFINE_TYPE (EditorEnchantSpellLanguage, editor_enchant_spell_language, EDITOR_TYPE_SPELL_LANGUAGE)
@@ -181,7 +182,7 @@ editor_enchant_spell_language_get_extra_word_chars (EditorSpellLanguage *languag
 
   g_assert (EDITOR_IS_SPELL_LANGUAGE (language));
 
-  return enchant_dict_get_extra_word_characters (self->native);
+  return self->extra_word_chars;
 }
 
 static void
@@ -189,6 +190,7 @@ editor_enchant_spell_language_constructed (GObject *object)
 {
   EditorEnchantSpellLanguage *self = (EditorEnchantSpellLanguage *)object;
   g_auto(GStrv) split = NULL;
+  const char *extra_word_chars;
   const char *code;
 
   g_assert (EDITOR_IS_ENCHANT_SPELL_LANGUAGE (self));
@@ -200,6 +202,19 @@ editor_enchant_spell_language_constructed (GObject *object)
 
   if ((split = editor_enchant_spell_language_split (self, g_get_real_name ())))
     editor_enchant_spell_language_add_all_to_session (self, (const char * const *)split);
+
+  if ((extra_word_chars = enchant_dict_get_extra_word_characters (self->native)))
+    {
+      const char *end_pos = NULL;
+
+      /* Sometimes we get invalid UTF-8 from enchant, so handle that directly.
+       * In particular, the data seems corrupted from Fedora.
+       */
+      if (g_utf8_validate (extra_word_chars, -1, &end_pos))
+        self->extra_word_chars = g_strdup (extra_word_chars);
+      else
+        self->extra_word_chars = g_strndup (extra_word_chars, end_pos - extra_word_chars);
+    }
 }
 
 static void


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