[gtksourceview] encoding: more robust GVariant parsing
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] encoding: more robust GVariant parsing
- Date: Fri, 24 Oct 2014 11:03:17 +0000 (UTC)
commit 098f30f56b1a48cfcc59c0a286eb965012fbf34d
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Oct 24 11:54:00 2014 +0200
encoding: more robust GVariant parsing
Translations cannot be trusted, so make the code more robust to parsing
errors.
Thanks to Марко М. Костић for the bug report.
https://bugzilla.redhat.com/show_bug.cgi?id=1155810
gtksourceview/gtksourceencoding.c | 37 +++++++++++++++++++++++++++++++++++--
1 files changed, 35 insertions(+), 2 deletions(-)
---
diff --git a/gtksourceview/gtksourceencoding.c b/gtksourceview/gtksourceencoding.c
index 05227ad..824d951 100644
--- a/gtksourceview/gtksourceencoding.c
+++ b/gtksourceview/gtksourceencoding.c
@@ -627,9 +627,11 @@ GSList *
_gtk_source_encoding_get_default_candidates (void)
{
const gchar *encodings_str;
+ const gchar *encodings_str_translated;
GVariant *encodings_variant;
const gchar **encodings_strv;
GSList *encodings_list;
+ GError *error = NULL;
/* Translators: This is the sorted list of encodings used by
* GtkSourceView for automatic detection of the file encoding. You may
@@ -643,10 +645,41 @@ _gtk_source_encoding_get_default_candidates (void)
* recognized encodings are used. See
* https://git.gnome.org/browse/gtksourceview/tree/gtksourceview/gtksourceencoding.c#n147
* for a list of supported encodings.
+ * Keep the same format: square brackets, single quotes, commas.
*/
- encodings_str = _("['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']");
+ encodings_str = N_("['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']");
+
+ encodings_str_translated = _(encodings_str);
+
+ encodings_variant = g_variant_parse (G_VARIANT_TYPE_STRING_ARRAY,
+ encodings_str_translated,
+ NULL,
+ NULL,
+ &error);
+
+ if (error != NULL)
+ {
+ const gchar * const *language_names = g_get_language_names ();
+
+ g_warning ("Error while parsing encodings list for locale %s:\n"
+ "Translated list: %s\n"
+ "Error message: %s",
+ language_names[0],
+ encodings_str_translated,
+ error->message);
+
+ g_error_free (error);
+ error = NULL;
+
+ encodings_variant = g_variant_parse (G_VARIANT_TYPE_STRING_ARRAY,
+ encodings_str,
+ NULL,
+ NULL,
+ &error);
+
+ g_assert_no_error (error);
+ }
- encodings_variant = g_variant_new_parsed (encodings_str);
g_variant_ref_sink (encodings_variant);
encodings_strv = g_variant_get_strv (encodings_variant, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]