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.
This commit is contained in:
Matt Broadway 2023-01-02 20:07:26 +00:00 committed by GitHub
parent ab4226e292
commit f8a6396cdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -585,11 +585,18 @@ def _update_details(button):
_details._text.set_markup(text) _details._text.set_markup(text)
def _make_text(items): 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 '<small><tt>' + text + '</tt></small>' return '<small><tt>' + text + '</tt></small>'
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): def _read_slow(device):
items = _details_items(selected_device, True) items = _details_items(selected_device, True)
items = _displayable_items(items)
text = _make_text(items) text = _make_text(items)
if device == _details._current_device: if device == _details._current_device:
GLib.idle_add(_set_details, text) GLib.idle_add(_set_details, text)