Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtk-WARNING when device name contains "markup" #2429

Closed
XeCycle opened this issue Jul 15, 2024 · 3 comments · Fixed by #2431 or #2432
Closed

Gtk-WARNING when device name contains "markup" #2429

XeCycle opened this issue Jul 15, 2024 · 3 comments · Fixed by #2431 or #2432

Comments

@XeCycle
Copy link

XeCycle commented Jul 15, 2024

blueman: 2.4.2
BlueZ: 5.77
Distribution: Arch Linux
Desktop environment: awesome wm, notification daemon dunst

My headset, Creative Zen Hybrid Pro, reports a weird name. As an example this reporter says their device name is "ZenHybridPro (SX:A0l9g7[m[`)"; mine is "ZenHybridPro (SX:p<>v......)". (I'm not sure whether this name can be linked to MAC or whatever, allow me to mask part of it). And blueman-applet frequently logs

(blueman-tray:15759): Gtk-WARNING **: 10:44:17.326: Failed to set text '音频和输入配置文件 on ZenHybridPro (SX:p<>v......)' from markup due to error parsing markup: Error on line 1 char 59: “>” is not a valid character following a “<” character; it may not begin an element name

The Chinese part means "audio and input profile". This is shown 3 times at applet startup, and also several times when device connects. I tried --loglevel debug but no relevant logs for this one.

@infirit
Copy link
Contributor

infirit commented Jul 15, 2024

Ugh, looks like we can't trust the name we get from BlueZ. I suspect the error is from here.

def _render_item(self, item: Union["MenuItemDict", "SubmenuItemDict"]) -> Dict[str, GLib.Variant]:

We probably need to escape here

"text": _("%(service)s on %(device)s") % {"service": item["name"], "device": item["alias"]},

@infirit
Copy link
Contributor

infirit commented Jul 15, 2024

Can you try below debugging (and possible fix) patch. It logs the the device name (alias) to the applet log so there may be something interesting in blueman-applet --loglevel debug.

diff --git a/blueman/plugins/applet/RecentConns.py b/blueman/plugins/applet/RecentConns.py
index 84ec37a07..28e825da5 100644
--- a/blueman/plugins/applet/RecentConns.py
+++ b/blueman/plugins/applet/RecentConns.py
@@ -1,5 +1,6 @@
 from gettext import gettext as _
 from operator import itemgetter
+import html
 import time
 import logging
 from typing import List, TYPE_CHECKING, Optional, Callable, cast, Union
@@ -167,8 +168,10 @@ class RecentConns(AppletPlugin, PowerStateListener):
         self.parent.Plugins.DBusService.connect_service(item["device"], item["uuid"], reply, err)
 
     def _build_menu_item(self, item: "Item") -> "SubmenuItemDict":
+        logging.debug(f"{item['name']} - {item['alias']}")
+        alias = html.escape(item["alias"])
         mitem: "SubmenuItemDict" = {
-            "text": _("%(service)s on %(device)s") % {"service": item["name"], "device": item["alias"]},
+            "text": _("%(service)s on %(device)s") % {"service": item["name"], "device": alias},
             "markup": True,
             "icon_name": item["mitem"]["icon_name"] if item["mitem"] is not None else item["icon"],
             "sensitive": item["device"] is not None,

@XeCycle
Copy link
Author

XeCycle commented Jul 16, 2024

@infirit Yes that fixes it!

infirit added a commit to infirit/blueman that referenced this issue Jul 16, 2024
infirit added a commit to infirit/blueman that referenced this issue Jul 16, 2024
infirit added a commit to infirit/blueman that referenced this issue Jul 16, 2024
@infirit infirit linked a pull request Jul 16, 2024 that will close this issue
infirit added a commit that referenced this issue Jul 24, 2024
For example in the StatusNotifierItem.

fixes #2429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants