# HG changeset patch # User Luke Schierer # Date 1094930338 0 # Node ID 5b4a0af99bf735eafa219fc69337c83c043ca7a6 # Parent ab342e285f3aaf1d9d529188edce662001f2b1f2 [gaim-migrate @ 10935] (15:16:26) datallah: LSchiere: are you still planning to commit that gtkimhtml change to HEAD? (15:16:37) LSchiere: datallah: yes let me do that now for those that don't remember, this makes pasting on win32 suck less committer: Tailor Script diff -r ab342e285f3a -r 5b4a0af99bf7 src/gtkimhtml.c --- a/src/gtkimhtml.c Sat Sep 11 16:55:09 2004 +0000 +++ b/src/gtkimhtml.c Sat Sep 11 19:18:58 2004 +0000 @@ -151,9 +151,11 @@ clipboard_win32_to_html(char *clipboard) { const char *header; const char *begin, *end; - gint start=0; - gint finish=0; + gint start = 0; + gint finish = 0; gchar *html; + gchar **split; + int clipboard_length = 0; #if 0 /* Debugging for Windows clipboard */ FILE *fd; @@ -165,25 +167,38 @@ fclose(fd); #endif - if (!(header = strstr(clipboard, "StartFragment:"))) + clipboard_length = strlen(clipboard); + + if (!(header = strstr(clipboard, "StartFragment:")) || (header - clipboard) >= clipboard_length) return NULL; - sscanf(header, "StartFragment:%d", &start); - header = strstr(clipboard, "EndFragment:"); + if (!(header = strstr(clipboard, "EndFragment:")) || (header - clipboard) >= clipboard_length) + return NULL; sscanf(header, "EndFragment:%d", &finish); + if (finish > clipboard_length) + finish = clipboard_length; + + if (start > finish) + start = finish; + begin = clipboard + start; - if (header == NULL) - end = clipboard + strlen(clipboard); - else - end = clipboard + finish; - - html = g_strstrip(g_strndup(begin, end-begin)); + end = clipboard + finish; + + html = g_strndup(begin, end - begin); + + /* any newlines in the string will now be \r\n, so we need to strip out the \r */ + split = g_strsplit(html, "\r\n", 0); + g_free(html); + html = g_strjoinv("\n", split); + g_strfreev(split); + + html = g_strstrip(html); #if 0 /* Debugging for Windows clipboard */ - gaim_debug_info("imhtml clipboard", "HTML fragment: %s\n", html); + gaim_debug_info("imhtml clipboard", "HTML fragment: '%s'\n", html); #endif return html;