[sushi] text: utf8-validate the text before inserting it into the buffer



commit 98b71c7e168cc0513f3a50641f8632f71aa923fb
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Tue Jul 26 16:49:23 2011 +0200

    text: utf8-validate the text before inserting it into the buffer
    
    https://bugzilla.gnome.org/show_bug.cgi?id=655007

 src/libsushi/sushi-text-loader.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
---
diff --git a/src/libsushi/sushi-text-loader.c b/src/libsushi/sushi-text-loader.c
index e566e09..60676a7 100644
--- a/src/libsushi/sushi-text-loader.c
+++ b/src/libsushi/sushi-text-loader.c
@@ -177,6 +177,14 @@ load_contents_async_ready_cb (GObject *source,
     return;
   }
 
+  if (!g_utf8_validate (contents, -1, NULL)) {
+    /* FIXME: we need to report the error */
+    g_print ("Can't load the text file as it has invalid characters");
+    g_free (contents);
+
+    return;
+  }
+
   gtk_source_buffer_begin_not_undoable_action (self->priv->buffer);
   gtk_text_buffer_set_text (GTK_TEXT_BUFFER (self->priv->buffer), contents, -1);
   gtk_source_buffer_end_not_undoable_action (self->priv->buffer);



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