Replace all occurrences of markup in notification.

fix_markup previously would only replace one occurrence of needle in the
notification string. So we'd end up with some markup's making it
through, if there was more than one of a particular kind.

Introduces new function string_replace_all and calls it from fix_markup.
This commit is contained in:
Matthew Todd 2013-01-16 21:15:23 -08:00
parent 1b90d82972
commit 3beb9e42dc
3 changed files with 31 additions and 15 deletions

30
dunst.c
View File

@ -874,23 +874,23 @@ char
return NULL; return NULL;
} }
str = string_replace(""", "\"", str); str = string_replace_all(""", "\"", str);
str = string_replace("'", "'", str); str = string_replace_all("'", "'", str);
str = string_replace("&", "&", str); str = string_replace_all("&", "&", str);
str = string_replace("&lt;", "<", str); str = string_replace_all("&lt;", "<", str);
str = string_replace("&gt;", ">", str); str = string_replace_all("&gt;", ">", str);
/* remove tags */ /* remove tags */
str = string_replace("<b>", "", str); str = string_replace_all("<b>", "", str);
str = string_replace("</b>", "", str); str = string_replace_all("</b>", "", str);
str = string_replace("<br>", " ", str); str = string_replace_all("<br>", " ", str);
str = string_replace("<br/>", " ", str); str = string_replace_all("<br/>", " ", str);
str = string_replace("<br />", " ", str); str = string_replace_all("<br />", " ", str);
str = string_replace("<i>", "", str); str = string_replace_all("<i>", "", str);
str = string_replace("</i>", "", str); str = string_replace_all("</i>", "", str);
str = string_replace("<u>", "", str); str = string_replace_all("<u>", "", str);
str = string_replace("</u>", "", str); str = string_replace_all("</u>", "", str);
str = string_replace("</a>", "", str); str = string_replace_all("</a>", "", str);
start = strstr(str, "<a href"); start = strstr(str, "<a href");
if (start != NULL) { if (start != NULL) {

12
utils.c
View File

@ -25,6 +25,18 @@ char *lskip(char *s)
return s; return s;
} }
char *string_replace_all(const char *needle, const char *replacement,
char *haystack)
{
char *start;
start = strstr(haystack, needle);
while(start != NULL) {
haystack = string_replace(needle, replacement, haystack);
start = strstr(haystack, needle);
}
return haystack;
}
char *string_replace(const char *needle, const char *replacement, char *string_replace(const char *needle, const char *replacement,
char *haystack) char *haystack)
{ {

View File

@ -4,6 +4,10 @@
char *rstrip(char *str); char *rstrip(char *str);
char *lskip(char *str); char *lskip(char *str);
/* replace all occurrences of needle with replacement in haystack */
char *string_replace_all(const char *needle, const char *replacement,
char *haystack);
/* replace needle with replacement in haystack */ /* replace needle with replacement in haystack */
char *string_replace(const char *needle, const char *replacement, char *string_replace(const char *needle, const char *replacement,
char *haystack); char *haystack);