Unverified Commit 88cfab3f authored by Clayton Craft's avatar Clayton Craft
Browse files

notification: escape notification message body

Notification daemons generally support markup in the message, and
when chatty tries to send a notification with text that fails markup
parsing then the notification does not contain the text at all.

E.g. receiving a SMS with the contents: "<wooohoo>" generates the
following warning in Phosh:

(phosh:22722): Gtk-WARNING **: 13:57:15.935: Failed to set text '<wooohoo>' from markup due to error parsing markup: Error on line 1 char 24: Element “markup” was closed, but the currently open element is “wooohoo”

I also took the liberty to reorder the switch cases to reduce duplicate
code.
parent d871df7b
Pipeline #73923 passed with stages
in 9 minutes and 14 seconds
......@@ -203,6 +203,7 @@ chatty_notification_show_message (ChattyNotification *self,
const char *name)
{
g_autofree char *title = NULL;
g_autofree char *body = NULL;
g_autoptr(LfbEvent) event = NULL;
ChattyItem *item;
ChattyMsgType type;
......@@ -231,37 +232,35 @@ chatty_notification_show_message (ChattyNotification *self,
type = chatty_message_get_msg_type (message);
switch (type) {
case CHATTY_MESSAGE_UNKNOWN:
case CHATTY_MESSAGE_TEXT:
case CHATTY_MESSAGE_HTML:
case CHATTY_MESSAGE_HTML_ESCAPED:
case CHATTY_MESSAGE_MATRIX_HTML:
case CHATTY_MESSAGE_LOCATION:
g_notification_set_body (self->notification, chatty_message_get_text (message));
break;
case CHATTY_MESSAGE_FILE:
g_notification_set_body (self->notification, "File");
body = g_strdup ("File");
break;
case CHATTY_MESSAGE_IMAGE:
g_notification_set_body (self->notification, "Picture");
body = g_strdup ("Picture");
break;
case CHATTY_MESSAGE_VIDEO:
g_notification_set_body (self->notification, "Video");
body = g_strdup ("Video");
break;
case CHATTY_MESSAGE_AUDIO:
g_notification_set_body (self->notification, "Audio File");
body = g_strdup ("Audio File");
break;
case CHATTY_MESSAGE_UNKNOWN:
case CHATTY_MESSAGE_TEXT:
case CHATTY_MESSAGE_HTML:
case CHATTY_MESSAGE_HTML_ESCAPED:
case CHATTY_MESSAGE_MATRIX_HTML:
case CHATTY_MESSAGE_LOCATION:
default:
g_notification_set_body (self->notification, chatty_message_get_text (message));
body = g_markup_escape_text (chatty_message_get_text (message), -1);
break;
}
g_notification_set_title (self->notification, title);
g_notification_set_body (self->notification, body);
g_notification_set_priority (self->notification, G_NOTIFICATION_PRIORITY_HIGH);
/* Delay the notification a bit so that we can squash multiple notifications
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment