Skip to content

Commit

Permalink
Fix empty notifications when '&' was used in text
Browse files Browse the repository at this point in the history
Seems that because it uses a subset of HTML, the text in notifications should
not use '&' directly, but encode it as & (else, the text of notification
is just empty, at least with notification-daemon and xfce4-notifyd)

So, when creating new notifications, we make sure to "convert" those '&' since
there can be some in e.g. a package description, which could be used as part
of the template (text is untouched on CLI output).
  • Loading branch information
jjacky committed Nov 19, 2012
1 parent 22dac20 commit e1a4eb5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gui.c
Expand Up @@ -77,7 +77,7 @@ show_notif (notif_t *notif)
{ {
NotifyNotification *notification; NotifyNotification *notification;


debug ("showing notif: %s", notif->summary); debug ("showing notif: %s\n%s\n--- EOF ---", notif->summary, notif->text);
notification = new_notification (notif->summary, notif->text); notification = new_notification (notif->summary, notif->text);
if (notif->type & CHECK_UPGRADES) if (notif->type & CHECK_UPGRADES)
{ {
Expand Down
58 changes: 56 additions & 2 deletions util-gtk.c
Expand Up @@ -187,8 +187,62 @@ NotifyNotification *
new_notification (const gchar *summary, const gchar *text) new_notification (const gchar *summary, const gchar *text)
{ {
NotifyNotification *notification; NotifyNotification *notification;

gchar *t = NULL;
notification = notify_notification_new (summary, text, NULL);
/* seems that because notifications use a subset of HTML, we need to use
* & to put the character '&' -- so let's deal with this, here because
* the text could have gone to CLI, where this replacement need not be
* done */
if (text)
{
gchar *s, *ss = text;
int diff = 0, alloc = 0;
while ((s = strchr (ss, '&')))
{
/* is this already & ? -- we assume here that there's never
* something like * or whatever, which should always be the case */
if (s[1] != 'a' && s[2] != 'm' && s[3] != 'p' && s[4] != ';')
{
/* do we need to (re)alloc some memory? */
if (diff + 5 > alloc)
{
if (alloc == 0)
{
alloc = strlen (text);
}
alloc += 24; /* should be more than enough, as that's 6 '&' */
t = realloc (t, sizeof (*t) * (alloc + 1));

/* first time? let's copy the text over */
if (diff == 0)
{
memcpy (t, text, strlen (text) + 1);
}
}
/* position of s in t */
int pos = (s - text) + diff;
/* move the text after the &, making room for amp; */
memcpy (t + pos + 4 + 1, s + 1, strlen (s + 1) + 1);
t[++pos] = 'a';
t[++pos] = 'm';
t[++pos] = 'p';
t[++pos] = ';';
/* t is now 4 bytes bigger than it was from text */
diff += 4;
ss = s + 1;
}
else
{
ss = s + 5;
}
}
}

notification = notify_notification_new (summary, (t) ? t : text, NULL);
if (t)
{
free (t);
}
if (config->notif_icon != ICON_NONE) if (config->notif_icon != ICON_NONE)
{ {
GtkWidget *w = NULL; GtkWidget *w = NULL;
Expand Down

0 comments on commit e1a4eb5

Please sign in to comment.