diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2015-07-21 16:41:48 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2015-07-21 16:41:48 +0200 |
commit | 4373d5d313fca77c79dd4287d87bf32815dc6196 (patch) | |
tree | f13562718b7c45bc1a0086684b15d39e2e1b9f7f /grc/gui/Utils.py | |
parent | 7345de003ff2f916f0e6344c12f1ae1fc95fdf54 (diff) |
grc: ensure only valid utf-8 is passed to markup_escape_text (fixes #813)
Diffstat (limited to 'grc/gui/Utils.py')
-rw-r--r-- | grc/gui/Utils.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py index 44df79f52c..624197f213 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)) |