summaryrefslogtreecommitdiff
path: root/grc/gui
diff options
context:
space:
mode:
authorDaniel Estévez <daniel@destevez.net>2020-09-19 14:12:31 +0200
committerMartin Braun <martin@gnuradio.org>2021-01-29 12:19:01 +0100
commit562ae285729fef946446c0c3dbf28b095a855e0c (patch)
treebcb7522d06c4c86d3a48784c2155ae8bea1a7ca4 /grc/gui
parent2ec31ce5759b051da6fb78de36f591687cb699c5 (diff)
grc: ensure that strings are valid utf8 when evaluating parameters
Some objects, notably PMTs can produce non-UTF-8 strings when their __str__() method is called. For instance >>> str(pmt.init_u8vector(1, [203])) '#[\udccb]' These kinds of strings eventually give a UnicodeEncodeError, for instance when calling print() or displaying them with GTK. Python3 strings are supposed to be valid UTF-8. When these objects are used inside block parameters in GRC, it will produce several tracebacks and hang up. This commit fixes the problem by sanitizing the strings to convert them to valid UTF-8. The sanitization uses the 'backslashreplace' error response from Python. Issue #3398 is caused by this problem. Signed-off-by: Martin Braun <martin@gnuradio.org>
Diffstat (limited to 'grc/gui')
-rw-r--r--grc/gui/VariableEditor.py3
-rw-r--r--grc/gui/canvas/param.py6
2 files changed, 9 insertions, 0 deletions
diff --git a/grc/gui/VariableEditor.py b/grc/gui/VariableEditor.py
index b243829197..d815e5ddd1 100644
--- a/grc/gui/VariableEditor.py
+++ b/grc/gui/VariableEditor.py
@@ -183,6 +183,9 @@ class VariableEditor(Gtk.VBox):
# Evaluate the params
for key in block.params:
evaluated = str(block.params[key].evaluate())
+ # ensure that evaluated is a UTF-8 string
+ # Old PMTs could produce non-UTF-8 strings
+ evaluated = evaluated.encode('utf-8', 'backslashreplace').decode('utf-8')
self.set_tooltip_text(evaluated)
# Evaluate the block value
diff --git a/grc/gui/canvas/param.py b/grc/gui/canvas/param.py
index 92d1f84941..3480d79618 100644
--- a/grc/gui/canvas/param.py
+++ b/grc/gui/canvas/param.py
@@ -73,6 +73,9 @@ class Param(CoreParam):
if hasattr(value, "__len__"):
tooltip_lines.append('Length: {}'.format(len(value)))
value = str(value)
+ # ensure that value is a UTF-8 string
+ # Old PMTs could produce non-UTF-8 strings
+ value = value.encode('utf-8', 'backslashreplace').decode('utf-8')
if len(value) > 100:
value = '{}...{}'.format(value[:50], value[-50:])
tooltip_lines.append('Value: ' + value)
@@ -139,6 +142,9 @@ class Param(CoreParam):
else:
# Other types
dt_str = str(e)
+ # ensure that value is a UTF-8 string
+ # Old PMTs could produce non-UTF-8 strings
+ dt_str = dt_str.encode('utf-8', 'backslashreplace').decode('utf-8')
# Done
return _truncate(dt_str, truncate)