changeset 24233:e0cfdf4a5a38

Make the CSS rgb() color parsing more robust. khc noted that it wouldn't work with "rgb (..." and I updated it to work with negative values as specified at http://www.w3.org/TR/CSS2/syndata.html#color-units References #7288
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 24 Oct 2008 17:42:32 +0000
parents 15c30a63f124
children 9f039d14bf35
files pidgin/gtkimhtml.c
diffstat 1 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkimhtml.c	Fri Oct 24 04:19:10 2008 +0000
+++ b/pidgin/gtkimhtml.c	Fri Oct 24 17:42:32 2008 +0000
@@ -2529,12 +2529,20 @@
 {
 	char *tmp = in_color;
 
-	if (*tmp == 'r' && *(++tmp) == 'g' && *(++tmp) == 'b'
-			&& *(++tmp) == '(' && *(++tmp)) {
+	if (*tmp == 'r' && *(++tmp) == 'g' && *(++tmp) == 'b' && *(++tmp)) {
 		int rgbval[] = {0, 0, 0};
 		int count = 0;
 		const char *v_start;
 
+		while (*tmp && g_ascii_isspace(*tmp))
+			tmp++;
+		if (*tmp != '(') {
+			/* We don't support rgba() */
+			purple_debug_warning("gtkimhtml", "Invalid rgb CSS color in '%s'!\n", in_color);
+			return in_color;
+		}
+		tmp++;
+
 		while (count < 3) {
 			/* Skip any leading spaces */
 			while (*tmp && g_ascii_isspace(*tmp))
@@ -2542,6 +2550,8 @@
 
 			/* Find the subsequent contiguous digits */
 			v_start = tmp;
+			if (*v_start == '-')
+				tmp++;
 			while (*tmp && g_ascii_isdigit(*tmp))
 				tmp++;