1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
From: Simon McVittie <smcv@debian.org>
Date: Sun, 30 Jan 2022 19:02:44 +0000
Subject: avahi-discover: Escape strings substituted into Pango markup
Otherwise, a TXT entry containing a URL with '&' will cause an error.
Signed-off-by: Simon McVittie <smcv@debian.org>
Forwarded: https://github.com/lathiat/avahi/pull/369
---
avahi-python/avahi-discover/avahi-discover.py | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/avahi-python/avahi-discover/avahi-discover.py b/avahi-python/avahi-discover/avahi-discover.py
index fddf4a5..9b31d8f 100755
--- a/avahi-python/avahi-discover/avahi-discover.py
+++ b/avahi-python/avahi-discover/avahi-discover.py
@@ -27,7 +27,7 @@ try:
gettext.textdomain(@GETTEXT_PACKAGE@)
import gi
gi.require_version('Gtk', '3.0')
- from gi.repository import Gtk, GObject
+ from gi.repository import Gtk, GObject, GLib
_ = gettext.gettext
except ImportError as e:
print("Sorry, to use this tool you need to install Avahi, pygtk and python-dbus.\n Error: %s" % e)
@@ -235,7 +235,10 @@ class Main_window:
txts = ""
txtd = self.pair_to_dict(txt)
for k,v in txtd.items():
- txts+="<b>" + _("TXT") + " <i>%s</i></b> = %s\n" % (k,v)
+ txts+="<b>" + _("TXT") + " <i>%s</i></b> = %s\n" % (
+ GLib.markup_escape_text(k),
+ GLib.markup_escape_text(v),
+ )
else:
txts = "<b>" + _("TXT Data:") + "</b> <i>" + _("empty") + "</i>"
@@ -249,7 +252,17 @@ class Main_window:
infos += "<b>" + _("Address:") + "</b> %s/%s:%i\n%s"
if isinstance(infos, bytes): # Python 2
infos = infos.decode("utf-8")
- infos = infos % (stype, name, domain, self.siocgifname(interface), self.protoname(protocol), host, address, port, txts.strip())
+ infos = infos % (
+ GLib.markup_escape_text(stype),
+ GLib.markup_escape_text(name),
+ GLib.markup_escape_text(domain),
+ GLib.markup_escape_text(self.siocgifname(interface)),
+ GLib.markup_escape_text(self.protoname(protocol)),
+ GLib.markup_escape_text(host),
+ GLib.markup_escape_text(address),
+ port,
+ txts.strip(),
+ )
self.info_label.set_markup(infos)
def insert_row(self, model,parent,
|