pidgin: 9ea3a420: Fix a bug in our outgoing yahoo message ...

markdoliner at pidgin.im markdoliner at pidgin.im
Fri Aug 21 03:05:36 EDT 2009


-----------------------------------------------------------------
Revision: 9ea3a4203902d1463984567e136de7aaf099b832
Ancestor: 9b09135cf7cd0b5af42c084e3df644e12ca01a06
Author: markdoliner at pidgin.im
Date: 2009-08-20T20:04:50
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/9ea3a4203902d1463984567e136de7aaf099b832

Modified files:
        libpurple/protocols/yahoo/util.c
        libpurple/tests/test_yahoo_util.c

ChangeLog: 

Fix a bug in our outgoing yahoo message formatting where messages
with variations in text color and font size/face could have incorrect
coloring

-------------- next part --------------
============================================================
--- libpurple/protocols/yahoo/util.c	05b35b77b7534019820b45088ffa9b302cdf9247
+++ libpurple/protocols/yahoo/util.c	b61962f831b0bc0ef57b498dd95648597bcb6357
@@ -712,6 +712,14 @@ static void parse_font_tag(GString *dest
 		g_string_append_printf(dest, "\033[%sm", attribute);
 		*colors = g_slist_prepend(*colors,
 				g_strdup_printf("\033[%sm", attribute));
+	} else {
+		/* We need to add a value to the colors stack even if we're not
+		 * setting a color because we ALWAYS pop exactly 1 element from
+		 * this stack for every </font> tag.  If we don't add anything
+		 * then we'll pop something that we shouldn't when we hit this
+		 * corresponding </font>. */
+		*colors = g_slist_prepend(*colors,
+				*colors ? g_strdup((*colors)->data) : g_strdup("\033[#000000m"));
 	}
 
 	attribute = g_datalist_get_data(&attributes, "face");
@@ -868,11 +876,9 @@ char *yahoo_html_to_codes(const char *sr
 						char *etag = tags->data;
 						tags = g_slist_delete_link(tags, tags);
 						g_string_append(dest, etag);
-						if (g_str_equal(etag, "</font>")) {
-							if (colors != NULL) {
-								g_free(colors->data);
-								colors = g_slist_delete_link(colors, colors);
-							}
+						if (colors != NULL) {
+							g_free(colors->data);
+							colors = g_slist_delete_link(colors, colors);
 						}
 						g_free(etag);
 					}
============================================================
--- libpurple/tests/test_yahoo_util.c	90d3df4d677945e76b4040312778d4fbc390ca72
+++ libpurple/tests/test_yahoo_util.c	0f68bbac30c09126a3e85b70d6aa5684c769b61d
@@ -149,7 +149,7 @@ START_TEST(test_html_to_codes)
 	assert_string_equal_free("mark at example.com",
 			yahoo_html_to_codes("<A HREF=\"mailto:mark at example.com\">mark at example.com</A>"));
 #if 0
-	assert_string_equal_free("http://pidgin.im/",
+	assert_string_equal_free("Pidgin (http://pidgin.im/)",
 			yahoo_html_to_codes("<A HREF=\"http://pidgin.im/\">Pidgin</A>"));
 #endif
 
@@ -160,12 +160,25 @@ START_TEST(test_html_to_codes)
 	/* font color */
 	assert_string_equal_free("\x1B[#E71414mred\x1B[#000000m",
 			yahoo_html_to_codes("<font color=\"#E71414\">red</font>"));
+	assert_string_equal_free("\x1B[#FF0000mred\x1B[#000000m \x1B[#0000FFmblue\x1B[#000000m black",
+			yahoo_html_to_codes("<font color=\"#FF0000\">red</font> <font color=\"#0000FF\">blue</font> black"));
 
 	/* font size */
 	assert_string_equal_free("<font size=\"10\">test</font>",
 			yahoo_html_to_codes("<font size=\"2\">test</font>"));
 	assert_string_equal_free("<font size=\"30\">test</font>",
 			yahoo_html_to_codes("<font size=\"6\">test</font>"));
+
+	/* combinations */
+	assert_string_equal_free("\x1B[#FF0000m<font size=\"8\">redsmall</font> rednormal\x1B[#000000m",
+			yahoo_html_to_codes("<font color=\"#FF0000\"><font size=\"1\">redsmall</font> rednormal</font>"));
+
+	assert_string_equal_free("\x1B[#FF0000m<font size=\"8\">redsmall</font> \x1B[#00FF00mgreennormal\x1B[#FF0000m rednormal\x1B[#000000m",
+			yahoo_html_to_codes("<font color=\"#FF0000\"><font size=\"1\">redsmall</font> <font color=\"#00FF00\">greennormal</font> rednormal</font>"));
+
+	/* This test case isn't correct, and so it's commented out */
+	assert_string_equal_free("\x1B[1mbold \x1B[#FF0000mred <font face=\"Comic Sans MS\" size=\"20\">larger \x1B[#000000mbacktoblack <font size=\"12\">normalsize</font>\x1B[#FF0000m</font>\x1B[#000000m\x1B[x1m",
+			yahoo_html_to_codes("<b>bold <font color=\"#FF0000\">red <font face=\"Comic Sans MS\" size=\"5\">larger <font color=\"#000000\">backtoblack <font size=\"3\">normalsize</font></font></font></font></b>"));
 }
 END_TEST
 


More information about the Commits mailing list