Mercurial > pidgin.yaz
diff src/html.c @ 5110:496ea7c1b77b
[gaim-migrate @ 5473]
it dawned on me that since this function is so good at validating html, it
might be pretty good at stripping html. so now we use it instead of
strip_html and jabber messages don't get stripped of valid < and > characters
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 11 Apr 2003 08:09:21 +0000 |
parents | b99910bfedd2 |
children | 5736055629cb |
line wrap: on
line diff
--- a/src/html.c Fri Apr 11 07:49:15 2003 +0000 +++ b/src/html.c Fri Apr 11 08:09:21 2003 +0000 @@ -344,6 +344,7 @@ c = p + 1; \ } else { \ xhtml = g_string_append(xhtml, "<"); \ + plain = g_string_append_c(plain, '<'); \ } \ continue; \ } \ @@ -357,29 +358,36 @@ pt->src_tag = x; \ pt->dest_tag = y; \ tags = g_list_prepend(tags, pt); \ + xhtml = g_string_append_c(xhtml, '>'); \ + } else { \ + xhtml = g_string_append(xhtml, "/>");\ } \ + c = strchr(c, '>') + 1; \ continue; \ } #define ALLOW_TAG(x) ALLOW_TAG_ALT(x, x) -char *html_to_xhtml(const char *html) { +void html_to_xhtml(const char *html, char **xhtml_out, char **plain_out) { GString *xhtml = g_string_new(""); + GString *plain = g_string_new(""); GList *tags = NULL, *tag; const char *q = NULL, *c = html; - char *ret; while(*c) { if(!q && (*c == '\"' || *c == '\'')) { q = c; xhtml = g_string_append_c(xhtml, *c); + plain = g_string_append_c(plain, *c); c++; } else if(q) { if(*c == *q) { q = NULL; } else if(*c == '\\') { xhtml = g_string_append_c(xhtml, *c); + plain = g_string_append_c(plain, *c); c++; } xhtml = g_string_append_c(xhtml, *c); + plain = g_string_append_c(plain, *c); c++; } else if(*c == '<') { if(*(c+1) == '/') { /* closing tag */ @@ -407,6 +415,7 @@ /* we tried to close a tag we never opened! escape it * and move on */ xhtml = g_string_append(xhtml, "<"); + plain = g_string_append_c(plain, '<'); c++; } } else { /* opening tag */ @@ -572,10 +581,12 @@ } xhtml = g_string_append(xhtml, "<"); + plain = g_string_append_c(plain, '<'); c++; } } else { xhtml = g_string_append_c(xhtml, *c); + plain = g_string_append_c(plain, *c); c++; } } @@ -585,7 +596,10 @@ tag = tag->next; } g_list_free(tags); - ret = g_strdup(xhtml->str); + if(xhtml_out) + *xhtml_out = g_strdup(xhtml->str); + if(plain_out) + *plain_out = g_strdup(plain->str); g_string_free(xhtml, TRUE); - return ret; + g_string_free(plain, TRUE); }