Fix: Escape markup text for notifications. (#976)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import AstalNotifd from 'gi://AstalNotifd?version=0.1';
|
import AstalNotifd from 'gi://AstalNotifd?version=0.1';
|
||||||
import { Gtk } from 'astal/gtk3';
|
import { Gtk } from 'astal/gtk3';
|
||||||
import { notifHasImg } from '../helpers';
|
import { notifHasImg, escapeMarkup } from '../helpers';
|
||||||
|
|
||||||
export const Body = ({ notification }: BodyProps): JSX.Element => {
|
export const Body = ({ notification }: BodyProps): JSX.Element => {
|
||||||
return (
|
return (
|
||||||
@@ -8,7 +8,7 @@ export const Body = ({ notification }: BodyProps): JSX.Element => {
|
|||||||
<label
|
<label
|
||||||
className={'notification-card-body-label'}
|
className={'notification-card-body-label'}
|
||||||
halign={Gtk.Align.START}
|
halign={Gtk.Align.START}
|
||||||
label={notification.body}
|
label={escapeMarkup(notification.body)}
|
||||||
maxWidthChars={!notifHasImg(notification) ? 35 : 28}
|
maxWidthChars={!notifHasImg(notification) ? 35 : 28}
|
||||||
lines={2}
|
lines={2}
|
||||||
truncate
|
truncate
|
||||||
@@ -16,7 +16,7 @@ export const Body = ({ notification }: BodyProps): JSX.Element => {
|
|||||||
justify={Gtk.Justification.LEFT}
|
justify={Gtk.Justification.LEFT}
|
||||||
hexpand
|
hexpand
|
||||||
useMarkup
|
useMarkup
|
||||||
onRealize={(self) => self.set_markup(notification.body)}
|
onRealize={(self) => self.set_markup(escapeMarkup(notification.body))}
|
||||||
/>
|
/>
|
||||||
</box>
|
</box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import AstalNotifd from 'gi://AstalNotifd?version=0.1';
|
|||||||
import options from 'src/configuration';
|
import options from 'src/configuration';
|
||||||
import { GLib } from 'astal';
|
import { GLib } from 'astal';
|
||||||
import { Gtk } from 'astal/gtk3';
|
import { Gtk } from 'astal/gtk3';
|
||||||
import { notifHasImg } from '../helpers';
|
import { notifHasImg, escapeMarkup } from '../helpers';
|
||||||
import { getNotificationIcon } from 'src/lib/shared/notifications';
|
import { getNotificationIcon } from 'src/lib/shared/notifications';
|
||||||
|
|
||||||
const { military } = options.menus.clock.time;
|
const { military } = options.menus.clock.time;
|
||||||
@@ -38,8 +38,8 @@ const SummaryLabel = ({ notification }: HeaderProps): JSX.Element => {
|
|||||||
<label
|
<label
|
||||||
className={'notification-card-header-label'}
|
className={'notification-card-header-label'}
|
||||||
halign={Gtk.Align.START}
|
halign={Gtk.Align.START}
|
||||||
onRealize={(self) => self.set_markup(notification.summary)}
|
onRealize={(self) => self.set_markup(escapeMarkup(notification.summary))}
|
||||||
label={notification.summary}
|
label={escapeMarkup(notification.summary)}
|
||||||
maxWidthChars={!notifHasImg(notification) ? 30 : 19}
|
maxWidthChars={!notifHasImg(notification) ? 30 : 19}
|
||||||
hexpand
|
hexpand
|
||||||
vexpand
|
vexpand
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import AstalNotifd from 'gi://AstalNotifd?version=0.1';
|
|||||||
import options from 'src/configuration';
|
import options from 'src/configuration';
|
||||||
import { isNotificationIgnored } from 'src/lib/shared/notifications';
|
import { isNotificationIgnored } from 'src/lib/shared/notifications';
|
||||||
import AstalHyprland from 'gi://AstalHyprland?version=0.1';
|
import AstalHyprland from 'gi://AstalHyprland?version=0.1';
|
||||||
|
import GLib from 'gi://GLib';
|
||||||
|
|
||||||
const notifdService = AstalNotifd.get_default();
|
const notifdService = AstalNotifd.get_default();
|
||||||
const hyprlandService = AstalHyprland.get_default();
|
const hyprlandService = AstalHyprland.get_default();
|
||||||
@@ -100,3 +101,13 @@ export const trackAutoTimeout = (): void => {
|
|||||||
notifdService.set_ignore_timeout(!shouldAutoDismiss);
|
notifdService.set_ignore_timeout(!shouldAutoDismiss);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escapes text for safe use in Pango markup
|
||||||
|
* Converts special XML characters to their entity representations
|
||||||
|
*
|
||||||
|
* @param text - The text to escape
|
||||||
|
*/
|
||||||
|
export const escapeMarkup = (text: string): string => {
|
||||||
|
return GLib.markup_escape_text(text, -1);
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user