comparison pidgin/gtkimhtml.c @ 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
comparison
equal deleted inserted replaced
24232:15c30a63f124 24233:e0cfdf4a5a38
2527 static gchar* 2527 static gchar*
2528 parse_css_color(gchar *in_color) 2528 parse_css_color(gchar *in_color)
2529 { 2529 {
2530 char *tmp = in_color; 2530 char *tmp = in_color;
2531 2531
2532 if (*tmp == 'r' && *(++tmp) == 'g' && *(++tmp) == 'b' 2532 if (*tmp == 'r' && *(++tmp) == 'g' && *(++tmp) == 'b' && *(++tmp)) {
2533 && *(++tmp) == '(' && *(++tmp)) {
2534 int rgbval[] = {0, 0, 0}; 2533 int rgbval[] = {0, 0, 0};
2535 int count = 0; 2534 int count = 0;
2536 const char *v_start; 2535 const char *v_start;
2536
2537 while (*tmp && g_ascii_isspace(*tmp))
2538 tmp++;
2539 if (*tmp != '(') {
2540 /* We don't support rgba() */
2541 purple_debug_warning("gtkimhtml", "Invalid rgb CSS color in '%s'!\n", in_color);
2542 return in_color;
2543 }
2544 tmp++;
2537 2545
2538 while (count < 3) { 2546 while (count < 3) {
2539 /* Skip any leading spaces */ 2547 /* Skip any leading spaces */
2540 while (*tmp && g_ascii_isspace(*tmp)) 2548 while (*tmp && g_ascii_isspace(*tmp))
2541 tmp++; 2549 tmp++;
2542 2550
2543 /* Find the subsequent contiguous digits */ 2551 /* Find the subsequent contiguous digits */
2544 v_start = tmp; 2552 v_start = tmp;
2553 if (*v_start == '-')
2554 tmp++;
2545 while (*tmp && g_ascii_isdigit(*tmp)) 2555 while (*tmp && g_ascii_isdigit(*tmp))
2546 tmp++; 2556 tmp++;
2547 2557
2548 if (tmp != v_start) { 2558 if (tmp != v_start) {
2549 char prev = *tmp; 2559 char prev = *tmp;