Fix/simplify notification_strip_markup

- Strip markup before interpreting entitites.
- Handle *any* tag uniformly (<span> is also handled by pango)
This commit is contained in:
Yuri D'Elia 2014-12-21 14:58:10 +01:00 committed by Eizen
parent 8ee86dc477
commit bed4877d7b

View File

@ -191,25 +191,8 @@ char *notification_strip_markup(char *str)
return NULL; return NULL;
} }
str = string_replace_all("&quot;", "\"", str); /* strip all tags */
str = string_replace_all("&apos;", "'", str); while ((start = strstr(str, "<")) != NULL) {
str = string_replace_all("&amp;", "&", str);
str = string_replace_all("&lt;", "<", str);
str = string_replace_all("&gt;", ">", str);
/* remove tags */
str = string_replace_all("<b>", "", str);
str = string_replace_all("</b>", "", str);
str = string_replace_all("<br>", " ", str);
str = string_replace_all("<br/>", " ", str);
str = string_replace_all("<br />", " ", str);
str = string_replace_all("<i>", "", str);
str = string_replace_all("</i>", "", str);
str = string_replace_all("<u>", "", str);
str = string_replace_all("</u>", "", str);
str = string_replace_all("</a>", "", str);
while ((start = strstr(str, "<a href")) != NULL) {
end = strstr(start, ">"); end = strstr(start, ">");
if (end != NULL) { if (end != NULL) {
replace_buf = strndup(start, end - start + 1); replace_buf = strndup(start, end - start + 1);
@ -220,16 +203,13 @@ char *notification_strip_markup(char *str)
} }
} }
while ((start = strstr(str, "<img src")) != NULL) { /* unquote the remainder */
end = strstr(start, "/>"); str = string_replace_all("&quot;", "\"", str);
if (end != NULL) { str = string_replace_all("&apos;", "'", str);
replace_buf = strndup(start, end - start + 2); str = string_replace_all("&amp;", "&", str);
str = string_replace(replace_buf, "", str); str = string_replace_all("&lt;", "<", str);
free(replace_buf); str = string_replace_all("&gt;", ">", str);
} else {
break;
}
}
return str; return str;
} }
@ -270,19 +250,25 @@ char *notification_replace_format(const char *needle, const char *replacement,
tmp = notification_quote_markup(tmp); tmp = notification_quote_markup(tmp);
ret = string_replace_all(needle, tmp, haystack); ret = string_replace_all(needle, tmp, haystack);
free(tmp); free(tmp);
} else if (!allow_markup) { } else {
tmp = strdup(replacement); tmp = strdup(replacement);
if (!settings.ignore_newline) { if (settings.ignore_newline) {
tmp = string_replace_all("<br>", " ", tmp);
tmp = string_replace_all("<br/>", " ", tmp);
tmp = string_replace_all("<br />", " ", tmp);
} else {
tmp = string_replace_all("<br>", "\n", tmp); tmp = string_replace_all("<br>", "\n", tmp);
tmp = string_replace_all("<br/>", "\n", tmp); tmp = string_replace_all("<br/>", "\n", tmp);
tmp = string_replace_all("<br />", "\n", tmp); tmp = string_replace_all("<br />", "\n", tmp);
} }
if (!allow_markup) {
tmp = notification_strip_markup(tmp); tmp = notification_strip_markup(tmp);
tmp = notification_quote_markup(tmp); tmp = notification_quote_markup(tmp);
}
ret = string_replace_all(needle, tmp, haystack); ret = string_replace_all(needle, tmp, haystack);
free(tmp); free(tmp);
} else {
ret = string_replace_all(needle, replacement, haystack);
} }
return ret; return ret;