changeset 8473:12fe38c195a6

[gaim-migrate @ 9206] " You can once again show how evil you are by typing >:) and getting it to render in spite of escaped HTML. This patch changes around the parsing code to catch smileys before eating just any HTML entity we bump into on the street. We try to catch entities at the beginning of smileys first, and if we're sure they're not smileys, then we eat them for breakfast. The patch also deals with eating any subsequent entities that may appear in any smileys (like :-&) so we don't end up with trailing leftovers. This patch description is making me hungry. FYI, I know this gtkimhtml is supposed to be not gaim dependent, but both the gaim_* functions that were preexisting and newly used in gtkimhtml code are all non-gaim dependent utility functions from util.c, so I felt their use was justified and acceptable." --Kevin Stange committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Fri, 19 Mar 2004 17:34:33 +0000
parents 6d1c5321c55e
children 8b62cc40069b
files src/gtkimhtml.c
diffstat 1 files changed, 42 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkimhtml.c	Fri Mar 19 09:33:35 2004 +0000
+++ b/src/gtkimhtml.c	Fri Mar 19 17:34:33 2004 +0000
@@ -999,6 +999,7 @@
 	GtkSmileyTree *tree;
 	GtkIMHtmlFontDetail *font;
 	char *sml = NULL;
+	char *unescaped = NULL;
 
 	if (fonts) {
 		font = fonts->data;
@@ -1013,7 +1014,9 @@
 	if (tree == NULL)
 		return FALSE;
 
-	*len = gtk_smiley_tree_lookup (tree, text);
+	unescaped = gaim_unescape_html(text);
+	*len = gtk_smiley_tree_lookup (tree, unescaped);
+	g_free(unescaped);
 	return (*len > 0);
 }
 
@@ -1917,6 +1920,44 @@
 			pos += tlen;
 			if(tag)
 				g_free(tag); /* This was allocated back in VALID_TAG() */
+		} else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) {
+			GtkIMHtmlFontDetail *fd;
+
+			gchar *sml = NULL;
+			gchar *unescaped = NULL;
+			gint length = 0;
+			if (fonts) {
+				fd = fonts->data;
+				sml = fd->sml;
+			}
+			if (url)
+				gtk_imhtml_insert_link(imhtml, url, ws);
+			else {
+				gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos);
+			}
+			unescaped = gaim_unescape_html(c);
+			wpos = g_snprintf (ws, smilelen + 1, "%s", unescaped);
+			g_free(unescaped);
+
+			gtk_imhtml_insert_smiley(imhtml, sml, ws);
+
+			ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
+			gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
+
+			while(length < smilelen)
+			{
+			  if(*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) {
+				  c += tlen;
+				  pos += tlen;
+			  } else {
+				  c++;
+				  pos++;
+			  }
+			  length++;
+			}
+
+			wpos = 0;
+			ws[0] = 0;
 		} else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) {
 			while(*amp) {
 				ws [wpos++] = *amp++;
@@ -1945,29 +1986,6 @@
 				 ws [wpos++] = *c++;
 				 pos++;
 			}
-		} else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) {
-			GtkIMHtmlFontDetail *fd;
-
-			gchar *sml = NULL;
-			if (fonts) {
-				fd = fonts->data;
-				sml = fd->sml;
-			}
-			if (url)
-				gtk_imhtml_insert_link(imhtml, url, ws);
-			else {
-				gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos);
-			}
-			wpos = g_snprintf (ws, smilelen + 1, "%s", c);
-			gtk_imhtml_insert_smiley(imhtml, sml, ws);
-
-			ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
-			gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
-
-			c += smilelen;
-			pos += smilelen;
-			wpos = 0;
-			ws[0] = 0;
 		} else if (*c) {
 			ws [wpos++] = *c++;
 			pos++;