From 88cfab3f98f78199854837642b137a0fd1ea5263 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Fri, 17 Dec 2021 14:54:55 -0800 Subject: [PATCH] notification: escape notification message body MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: "" generates the following warning in Phosh: (phosh:22722): Gtk-WARNING **: 13:57:15.935: Failed to set text '' 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. --- src/chatty-notification.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/chatty-notification.c b/src/chatty-notification.c index b096cd95..e575ebab 100644 --- a/src/chatty-notification.c +++ b/src/chatty-notification.c @@ -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 -- GitLab