Skip to content

Commit ce4ffa0

Browse files
committed
Merge remote-tracking branch 'origin/pr/51'
* origin/pr/51: Escape application names for GMarkup
2 parents 9586eda + b2e036c commit ce4ffa0

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

qubes_menu/app_widgets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"""
2323
import subprocess
2424
import logging
25+
import urllib.parse
2526
from typing import Optional, List
2627
from functools import reduce
2728

@@ -75,7 +76,8 @@ def __init__(self, app_info: ApplicationInfo, **properties):
7576
self.connect("drag-data-get", self._on_drag_data_get)
7677

7778
def _on_drag_data_get(self, _widget, _drag_context, data, _info, _time):
78-
data.set_uris(['file://' + str(self.app_info.file_path)])
79+
data.set_uris(['file://' +
80+
urllib.parse.quote(str(self.app_info.file_path))])
7981

8082
def show_menu(self, _widget, event):
8183
"""

qubes_menu/utils.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,14 @@ def load_icon(icon_name,
5858
pixbuf.fill(0x000)
5959
return pixbuf
6060

61-
6261
def show_error(title, text):
6362
"""
6463
Helper function to display error messages.
6564
"""
6665
dialog = Gtk.MessageDialog(
6766
None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK)
6867
dialog.set_title(title)
69-
dialog.set_markup(text)
68+
dialog.set_markup(GLib.markup_escape_text(text))
7069
dialog.connect("response", lambda *x: dialog.destroy())
7170
dialog.show()
7271

@@ -94,7 +93,7 @@ def text_search(search_word: str, text_words: List[str]):
9493

9594

9695
def highlight_words(labels: List[Gtk.Label], search_words: List[str],
97-
hl_tag: Optional[str] = None):
96+
hl_tag: Optional[str] = None) -> None:
9897
"""Highlight provided search_words in the provided labels."""
9998
if not labels:
10099
return
@@ -113,7 +112,7 @@ def highlight_words(labels: List[Gtk.Label], search_words: List[str],
113112
for label in labels:
114113
text = label.get_text()
115114
# remove existing highlighting
116-
label.set_markup(text)
115+
label.set_markup(GLib.markup_escape_text(text))
117116
search_text = text.lower()
118117
found_intervals = []
119118
for word in search_words:
@@ -134,12 +133,17 @@ def highlight_words(labels: List[Gtk.Label], search_words: List[str],
134133
else:
135134
result_intervals.append(interval)
136135

137-
for interval in reversed(result_intervals):
138-
start, end = interval
139-
text = text[:start] + hl_tag + \
140-
text[start:end] + '</span>' + text[end:]
141-
142-
label.set_markup(text)
136+
markup_list = []
137+
last_start = 0
138+
for start, end in reversed(result_intervals):
139+
markup_list.append(GLib.markup_escape_text(text[last_start:start]))
140+
markup_list.append(hl_tag)
141+
markup_list.append(GLib.markup_escape_text(text[start:end]))
142+
markup_list.append('</span>')
143+
last_start = end
144+
markup_list.append(GLib.markup_escape_text(text[last_start:]))
145+
146+
label.set_markup("".join(markup_list))
143147

144148

145149
def get_visible_child(widget: Gtk.Container, reverse=False):

0 commit comments

Comments
 (0)