changeset 9777:8d891252f2ac

[gaim-migrate @ 10645] URLs containing ' will open correctly. There was some over-zealous double-quotation mark usage in gtknotify.c. That may have been my fault. Also escape the URLs in debug and gaim_notify messages. Also refactored gaim_escape_html() a tad bit. There is nothing wrong with exiting out of a function early. In the abnormal case that html==NULL, we just exit the function. It makes the meat of the function nested one fewer level. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 19 Aug 2004 01:45:30 +0000
parents 1e5ef71c9583
children 3d40125495e3
files ChangeLog src/gtknotify.c src/util.c
diffstat 3 files changed, 42 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Aug 19 01:13:58 2004 +0000
+++ b/ChangeLog	Thu Aug 19 01:45:30 2004 +0000
@@ -21,6 +21,7 @@
 	* Better file transfer cancel messages for AIM (Dave West)
 	* Buddy list tooltips display in more appropriate positions when
 	  using multiple monitors (Dave West)
+	* Better parsing of URLs containing special characters
 
 version 0.81 (08/05/2004):
 	New Features:
--- a/src/gtknotify.c	Thu Aug 19 01:13:58 2004 +0000
+++ b/src/gtknotify.c	Thu Aug 19 01:45:30 2004 +0000
@@ -407,20 +407,18 @@
 static gint
 uri_command(const char *command, gboolean sync)
 {
+	gchar *escaped, *tmp;
 	GError *error = NULL;
 	gint ret = 0;
 
-	gaim_debug_misc("gtknotify", "Executing %s\n", command);
+	escaped = gaim_escape_html(command);
+	gaim_debug_misc("gtknotify", "Executing %s\n", escaped);
 
 	if (!gaim_program_is_valid(command))
 	{
-		gchar *tmp;
-
-		tmp = g_strdup_printf(_("The browser command \"%s\" is invalid."),
-							  command ? command : "(none)");
-
+		tmp = g_strdup_printf(_("The browser command <b>%s</b> is invalid."),
+							  escaped ? escaped : "(none)");
 		gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
-
 		g_free(tmp);
 
 	}
@@ -430,11 +428,9 @@
 
 		if (!g_spawn_command_line_sync(command, NULL, NULL, &status, &error))
 		{
-			char *tmp = g_strdup_printf(_("Error launching \"%s\": %s"),
-										command, error->message);
-
+			tmp = g_strdup_printf(_("Error launching <b>%s</b>: %s"),
+										escaped, error->message);
 			gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
-
 			g_free(tmp);
 			g_error_free(error);
 		}
@@ -445,16 +441,16 @@
 	{
 		if (!g_spawn_command_line_async(command, &error))
 		{
-			char *tmp = g_strdup_printf(_("Error launching \"%s\": %s"),
-										command, error->message);
-
+			tmp = g_strdup_printf(_("Error launching <b>%s</b>: %s"),
+										escaped, error->message);
 			gaim_notify_error(NULL, NULL, _("Unable to open URL"), tmp);
-
 			g_free(tmp);
 			g_error_free(error);
 		}
 	}
 
+	g_free(escaped);
+
 	return ret;
 }
 #endif /* _WIN32 */
@@ -515,15 +511,15 @@
 
 		if (place == GAIM_BROWSER_NEW_WINDOW)
 			remote_command = g_strdup_printf("%s %s -remote "
-											 "\"openURL(\"%s\",new-window)\"",
+											 "\"openURL(%s,new-window)\"",
 											 web_browser, args, uri);
 		else if (place == GAIM_BROWSER_NEW_TAB)
 			remote_command = g_strdup_printf("%s %s -remote "
-											 "\"openURL(\"%s\",new-tab)\"",
+											 "\"openURL(%s,new-tab)\"",
 											 web_browser, args, uri);
 		else if (place == GAIM_BROWSER_CURRENT)
 			remote_command = g_strdup_printf("%s %s -remote "
-											 "\"openURL(\"%s\")\"",
+											 "\"openURL(%s)\"",
 											 web_browser, args, uri);
 	}
 	else if (!strcmp(web_browser, "netscape"))
@@ -533,13 +529,13 @@
 		if (place == GAIM_BROWSER_NEW_WINDOW)
 		{
 			remote_command = g_strdup_printf("netscape -remote "
-											 "\"openURL(\"%s\",new-window)\"",
+											 "\"openURL(%s,new-window)\"",
 											 uri);
 		}
 		else if (place == GAIM_BROWSER_CURRENT)
 		{
 			remote_command = g_strdup_printf("netscape -remote "
-											 "\"openURL(\"%s\")\"", uri);
+											 "\"openURL(%s)\"", uri);
 		}
 	}
 	else if (!strcmp(web_browser, "opera"))
@@ -551,7 +547,7 @@
 		else if (place == GAIM_BROWSER_CURRENT)
 		{
 			remote_command = g_strdup_printf("opera -remote "
-											 "\"openURL(\"%s\")\"", uri);
+											 "\"openURL(%s)\"", uri);
 			command = g_strdup_printf("opera \"%s\"", uri);
 		}
 		else
--- a/src/util.c	Thu Aug 19 01:13:58 2004 +0000
+++ b/src/util.c	Thu Aug 19 01:45:30 2004 +0000
@@ -1652,36 +1652,33 @@
 
 char *
 gaim_escape_html(const char *html) {
-	char *escaped = NULL;
-
-	if (html != NULL) {
-		const char *c = html;
-		GString *ret = g_string_new("");
-		while (*c) {
-			switch(*c) {
-				case '&':
-					ret = g_string_append(ret, "&amp;");
-					break;
-				case '<':
-					ret = g_string_append(ret, "&lt;");
-					break;
-				case '>':
-					ret = g_string_append(ret, "&gt;");
-					break;
-				case '"':
-					ret = g_string_append(ret, "&quot;");
-					break;
-				default:
-					ret = g_string_append_c(ret, *c);
-			}
-			c++;
+	const char *c = html;
+	GString *ret = g_string_new("");
+
+	if (html == NULL)
+		return NULL;
+
+	while (*c) {
+		switch (*c) {
+			case '&':
+				ret = g_string_append(ret, "&amp;");
+				break;
+			case '<':
+				ret = g_string_append(ret, "&lt;");
+				break;
+			case '>':
+				ret = g_string_append(ret, "&gt;");
+				break;
+			case '"':
+				ret = g_string_append(ret, "&quot;");
+				break;
+			default:
+				ret = g_string_append_c(ret, *c);
 		}
-
-		escaped = ret->str;
-		g_string_free(ret, FALSE);
+		c++;
 	}
 
-	return escaped;
+	return g_string_free(ret, FALSE);
 }
 
 char *