From f8a6396cdfd9eb6846099cdbc7ddf72051d34608 Mon Sep 17 00:00:00 2001 From: Matt Broadway Date: Mon, 2 Jan 2023 20:07:26 +0000 Subject: [PATCH] ui: Filter and escape technical detail fields (#1953) Since the values for the 'technical details' fields are arbitrary some characters need to be filtered out for them to display properly. markup characters such as < or > are now escaped and null characters are removed. Empty fields are no longer displayed in technical details. --- lib/solaar/ui/window.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index 366773af..e32a0898 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -585,11 +585,18 @@ def _update_details(button): _details._text.set_markup(text) def _make_text(items): - text = '\n'.join('%-13s: %s' % i for i in items) + text = '\n'.join('%-13s: %s' % (name, value) for name, value in items) return '' + text + '' + def _displayable_items(items): + for name, value in items: + value = GLib.markup_escape_text(str(value).replace('\x00', '')).strip() + if value: + yield name, value + def _read_slow(device): items = _details_items(selected_device, True) + items = _displayable_items(items) text = _make_text(items) if device == _details._current_device: GLib.idle_add(_set_details, text)