From 3bdf5f30d2bb21546dc56f20e56f2b7292eeebdd Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Mon, 20 May 2024 14:23:30 +0200 Subject: [PATCH] Introduce _artwork_infos(): properly escape lines A comment can contain html-like tags --- picard/ui/infodialog.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/picard/ui/infodialog.py b/picard/ui/infodialog.py index d2990a731..5c3cc997d 100644 --- a/picard/ui/infodialog.py +++ b/picard/ui/infodialog.py @@ -205,6 +205,17 @@ class InfoDialog(PicardDialog): lambda s: '%s' % (color, text_as_html(s)), errors)) self.ui.error.setText(text + '
') + def _artwork_infos(self, image): + """Information about image, as list of strings""" + if image.comment: + yield image.comment + bytes_size_decimal = bytes2human.decimal(image.datalength) + bytes_size_binary = bytes2human.binary(image.datalength) + yield f"{bytes_size_decimal} ({bytes_size_binary})" + if image.width and image.height: + yield f"{image.width} x {image.height}" + yield image.mimetype + def _display_artwork_image_cell(self, row_index, source): """Display artwork image, depending on source (new/orig), in the proper column""" image = self.artwork_rows[row_index][source] @@ -244,17 +255,8 @@ class InfoDialog(PicardDialog): 'tempfile': image.tempfile_filename, 'sourcefile': image.source, }) - infos = [] - if image.comment: - infos.append(image.comment) - infos.append("%s (%s)" % - (bytes2human.decimal(image.datalength), - bytes2human.binary(image.datalength))) - if image.width and image.height: - infos.append("%d x %d" % (image.width, image.height)) - infos.append(image.mimetype) - - img_wgt = ArtworkCoverWidget(pixmap=pixmap, text="\n".join(infos)) + infos = "
".join(escape(t) for t in self._artwork_infos(image)) + img_wgt = ArtworkCoverWidget(pixmap=pixmap, text=infos) self.artwork_table.setCellWidget(row_index, col_index, img_wgt) self.artwork_table.setItem(row_index, col_index, item)