Browse Source

Escape label name to support labels like <cat>, <background>

Kentaro Wada 2 năm trước cách đây
mục cha
commit
819a93cbbc
2 tập tin đã thay đổi với 6 bổ sung3 xóa
  1. 3 2
      labelme/app.py
  2. 3 1
      labelme/widgets/unique_label_qlist_widget.py

+ 3 - 2
labelme/app.py

@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 
 import functools
+import html
 import math
 import os
 import os.path as osp
@@ -1076,7 +1077,7 @@ class MainWindow(QtWidgets.QMainWindow):
         if shape.group_id is None:
             item.setText(
                 '{} <font color="#{:02x}{:02x}{:02x}">●</font>'.format(
-                    shape.label, *shape.fill_color.getRgb()[:3]
+                    html.escape(shape.label), *shape.fill_color.getRgb()[:3]
                 )
             )
         else:
@@ -1147,7 +1148,7 @@ class MainWindow(QtWidgets.QMainWindow):
         self._update_shape_color(shape)
         label_list_item.setText(
             '{} <font color="#{:02x}{:02x}{:02x}">●</font>'.format(
-                text, *shape.fill_color.getRgb()[:3]
+                html.escape(text), *shape.fill_color.getRgb()[:3]
             )
         )
 

+ 3 - 1
labelme/widgets/unique_label_qlist_widget.py

@@ -1,5 +1,7 @@
 # -*- encoding: utf-8 -*-
 
+import html
+
 from qtpy.QtCore import Qt
 from qtpy import QtWidgets
 
@@ -32,7 +34,7 @@ class UniqueLabelQListWidget(EscapableQListWidget):
         else:
             qlabel.setText(
                 '{} <font color="#{:02x}{:02x}{:02x}">●</font>'.format(
-                    label, *color
+                    html.escape(label), *color
                 )
             )
         qlabel.setAlignment(Qt.AlignBottom)