commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 02/06: grc: ensure only valid utf-8 is pass


From: git
Subject: [Commit-gnuradio] [gnuradio] 02/06: grc: ensure only valid utf-8 is passed to markup_escape_text (fixes #813)
Date: Fri, 24 Jul 2015 15:23:08 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch maint
in repository gnuradio.

commit 4373d5d313fca77c79dd4287d87bf32815dc6196
Author: Sebastian Koslowski <address@hidden>
Date:   Tue Jul 21 16:41:48 2015 +0200

    grc: ensure only valid utf-8 is passed to markup_escape_text (fixes #813)
---
 grc/gui/Utils.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index 44df79f..624197f 100644
--- a/grc/gui/Utils.py
+++ b/grc/gui/Utils.py
@@ -90,6 +90,17 @@ def get_angle_from_coordinates((x1, y1), (x2, y2)):
         return 270 if y2 > y1 else 90
 
 
+def encode(value):
+    """Make sure that we pass only valid utf-8 strings into markup_escape_text.
+
+    Older versions of glib seg fault if the last byte starts a multi-byte
+    character.
+    """
+
+    valid_utf8 = value.decode('utf-8', errors='ignore').encode('utf-8')
+    return gobject.markup_escape_text(valid_utf8)
+
+
 def parse_template(tmpl_str, **kwargs):
     """
     Parse the template string with the given args.
@@ -101,13 +112,7 @@ def parse_template(tmpl_str, **kwargs):
     Returns:
         a string of the parsed template
     """
-    kwargs['encode'] = gobject.markup_escape_text
-    #try:
-    #   cat = str(Template(tmpl_str, kwargs))
-    #except TypeError:
-    #   print 'guppy'
-    #   print tmpl_str
-    #   print str(kwargs['param'].get_error_messages())
+    kwargs['encode'] = encode
     return str(Template(tmpl_str, kwargs))
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]