From 6b0e2d731c02ac18f0ed0dcbcd8b815859c210b1 Mon Sep 17 00:00:00 2001 From: vilhalmer Date: Sun, 14 Oct 2018 12:41:57 -0400 Subject: [PATCH 1/2] Escape invalid markup even if markup is enabled --- notification.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notification.c b/notification.c index fe0d51b0..cb9aac79 100644 --- a/notification.c +++ b/notification.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #ifdef __linux__ #include @@ -226,7 +227,7 @@ size_t format_text(const char *format, char *buf, mako_format_func_t format_func } size_t value_len; - if (!markup) { + if (!markup || !pango_parse_markup(value, -1, 0, NULL, NULL, NULL, NULL)) { char *escaped = NULL; if (buf != NULL) { escaped = buf + len; From 1e4f2c5beaf79ee14ce36bd6b67f50f0433886c3 Mon Sep 17 00:00:00 2001 From: vilhalmer Date: Sun, 14 Oct 2018 12:46:56 -0400 Subject: [PATCH 2/2] Always allow markup from configuration --- notification.c | 2 +- render.c | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/notification.c b/notification.c index cb9aac79..079f3991 100644 --- a/notification.c +++ b/notification.c @@ -187,7 +187,7 @@ char *format_notif_text(char variable, bool *markup, void *data) { case 's': return strdup(notif->summary); case 'b': - *markup = true; + *markup = notif->style.markup; return strdup(notif->body); } return NULL; diff --git a/render.c b/render.c index 896ce401..7b0b9f3c 100644 --- a/render.c +++ b/render.c @@ -101,19 +101,15 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, pango_font_description_free(desc); PangoAttrList *attrs = NULL; - if (style->markup) { - GError *error = NULL; - char *buf = NULL; - if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) { - pango_layout_set_text(layout, buf, -1); - free(buf); - } else { - fprintf(stderr, "cannot parse pango markup: %s\n", error->message); - g_error_free(error); - // fallback to plain text - pango_layout_set_text(layout, text, -1); - } + GError *error = NULL; + char *buf = NULL; + if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) { + pango_layout_set_text(layout, buf, -1); + free(buf); } else { + fprintf(stderr, "cannot parse pango markup: %s\n", error->message); + g_error_free(error); + // fallback to plain text pango_layout_set_text(layout, text, -1); }