Desktop notifications: Fix limited HTML markup in the body text being rendered as HTML on some Linux systems

Fix #7671
This commit is contained in:
Kovid Goyal
2024-07-27 21:19:46 +05:30
parent 54b328710b
commit 45a3a655a7
2 changed files with 9 additions and 6 deletions

View File

@@ -56,7 +56,8 @@ longer than ``2048`` bytes, *before being encoded*.
Both the ``title`` and ``body`` payloads must be either UTF-8 encoded plain Both the ``title`` and ``body`` payloads must be either UTF-8 encoded plain
text with no embedded escape codes, or UTF-8 text that is :rfc:`base64 <4648>` text with no embedded escape codes, or UTF-8 text that is :rfc:`base64 <4648>`
encoded, in which case there must be an ``e=1`` key in the metadata to indicate encoded, in which case there must be an ``e=1`` key in the metadata to indicate
the payload is :rfc:`base64 <4648>` encoded. the payload is :rfc:`base64 <4648>` encoded. No HTML or other markup in the
plain text is allowed. It is strictly plain text, to be interpreted as such.
Being informed when user activates the notification Being informed when user activates the notification
------------------------------------------------------- -------------------------------------------------------

View File

@@ -369,7 +369,6 @@ class DesktopIntegration:
timeout: int = -1, timeout: int = -1,
application: str = 'kitty', application: str = 'kitty',
icon_name: str = '', icon_path: str = '', icon_name: str = '', icon_path: str = '',
subtitle: Optional[str] = None,
urgency: Urgency = Urgency.Normal, urgency: Urgency = Urgency.Normal,
) -> int: ) -> int:
raise NotImplementedError('Implement me in subclass') raise NotImplementedError('Implement me in subclass')
@@ -408,15 +407,18 @@ class MacOSIntegration(DesktopIntegration):
timeout: int = -1, timeout: int = -1,
application: str = 'kitty', application: str = 'kitty',
icon_name: str = '', icon_path: str = '', icon_name: str = '', icon_path: str = '',
subtitle: Optional[str] = None,
urgency: Urgency = Urgency.Normal, urgency: Urgency = Urgency.Normal,
) -> int: ) -> int:
desktop_notification_id = next(self.id_counter) desktop_notification_id = next(self.id_counter)
from .fast_data_types import cocoa_send_notification from .fast_data_types import cocoa_send_notification
# If the body is not set macos makes the title the body and uses # If the body is not set macos makes the title the body and uses
# "kitty" as the title. So use a single space for the body in this # "kitty" as the title. So use a single space for the body in this
# case. # case. Although https://developer.apple.com/documentation/usernotifications/unnotificationcontent/body?language=objc
cocoa_send_notification(str(desktop_notification_id), title, body or ' ', subtitle, urgency.value) # says printf style strings are stripped this doesnt actually happen,
# so dont double %
# for %% escaping.
body = (body or ' ')
cocoa_send_notification(str(desktop_notification_id), title, body, '', urgency.value)
return desktop_notification_id return desktop_notification_id
def notification_activated(self, event: str, ident: str) -> None: def notification_activated(self, event: str, ident: str) -> None:
@@ -491,11 +493,11 @@ class FreeDesktopIntegration(DesktopIntegration):
timeout: int = -1, timeout: int = -1,
application: str = 'kitty', application: str = 'kitty',
icon_name: str = '', icon_path: str = '', icon_name: str = '', icon_path: str = '',
subtitle: Optional[str] = None,
urgency: Urgency = Urgency.Normal, urgency: Urgency = Urgency.Normal,
) -> int: ) -> int:
from .fast_data_types import dbus_send_notification from .fast_data_types import dbus_send_notification
app_icon = icon_name or icon_path or get_custom_window_icon()[1] or logo_png_file app_icon = icon_name or icon_path or get_custom_window_icon()[1] or logo_png_file
body = body.replace('<', '<\u200c') # prevent HTML tags from being recognized
desktop_notification_id = dbus_send_notification( desktop_notification_id = dbus_send_notification(
app_name=application, app_icon=app_icon, title=title, body=body, timeout=timeout, urgency=urgency.value) app_name=application, app_icon=app_icon, title=title, body=body, timeout=timeout, urgency=urgency.value)
if debug_desktop_integration: if debug_desktop_integration: