summaryrefslogtreecommitdiff
path: root/grc/gui/VariableEditor.py
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/VariableEditor.py
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/VariableEditor.py')
-rw-r--r--grc/gui/VariableEditor.py3
1 files changed, 3 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