[Nautilus-list] bug 1462
- From: Kenneth Kocienda <kocienda kocienda com>
- To: darin eazel com
- Cc: nautilus-list lists eazel com
- Subject: [Nautilus-list] bug 1462
- Date: Thu, 24 Aug 2000 04:54:20 -0700
My attention will be diverted onto other things for a few days, but I
wanted to show you the progress I have made on bug 1462.
I have not had the chance to do the testing that I would like, but from
the patch you can see the interface, and the direction the
implementation is taking.
The patch seems to work on my machine, but YMMV. I will try to pick up
the loose ends again next week.
Darin Adler wrote:
>
> on 8/22/00 6:52 PM, Kenneth Kocienda at kocienda eazel com wrote:
>
> > For 1462 - File names containing space don't launch right, your
idea to
> > use single quotes won't work in one very important respect, and I
quote
> > the bash man page: "Enclosing characters in single quotes preserves
the
> > literal value of each character within the quotes. A single quote
may
> > not occur between single quotes, even when preceded by a
backslash."
>
> My approach for this was going to be the following:
>
> to quote: a#d'x"x
> you do this: 'a#d'\''x"x'
>
> This ends the quoting, inserts a single quote, and then starts the
quoting
> again. So the quote character turns into the 4-character sequence
'\''.
>
> -- Darin
>
> _______________________________________________
> Nautilus-list mailing list
> Nautilus-list lists eazel com
? 1462_patch2.txt
Index: libnautilus-extensions/nautilus-file-utilities.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-extensions/nautilus-file-utilities.c,v
retrieving revision 1.41
diff -U3 -r1.41 nautilus-file-utilities.c
--- libnautilus-extensions/nautilus-file-utilities.c 2000/08/07 23:55:50 1.41
+++ libnautilus-extensions/nautilus-file-utilities.c 2000/08/23 04:43:23
@@ -414,6 +414,56 @@
return !is_local;
}
+/*
+ * Transform a path so it safe to pass to the system shell
+ * This function returns a newly-allocated string
+ * that transforms the input string by enclosing it in single quotes,
+ * and handling all embedded single quotes in the input string by
+ * escaping them with this four-character sequence: '\''
+ */
+char *
+nautilus_get_shell_escaped_path (const char *path) {
+ char *result;
+ int len;
+ int i; /* index into path string */
+ int j; /* index into result string */
+
+ i = 0;
+ len = 0;
+ while (path[i] != '\0') {
+ /* add 3 for each single quote character */
+ if (path[i] == '\'') {
+ len += 3;
+ }
+ i++;
+ len++;
+ }
+ /* allocate len + 3 to account for enclosing quotes and trailing \0 */
+ result = g_malloc (len + 3);
+
+ /* now do the escaping */
+ i = 0;
+ j = 0;
+ result[j++] = '\'';
+ while (path[i] != '\0') {
+ if (path[i] == '\'') {
+ result[j++] = '\'';
+ result[j++] = '\\';
+ result[j++] = '\'';
+ result[j++] = '\'';
+ }
+ else {
+ result[j] = path[i];
+ j++;
+ }
+ i++;
+ }
+ result[j++] = '\'';
+ result[j] = '\0';
+
+ return result;
+}
+
/* FIXME: Callers just use this and dereference so we core dump if
* pixmaps are missing. That is lame.
Index: libnautilus-extensions/nautilus-file-utilities.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-extensions/nautilus-file-utilities.h,v
retrieving revision 1.14
diff -U3 -r1.14 nautilus-file-utilities.h
--- libnautilus-extensions/nautilus-file-utilities.h 2000/07/26 03:07:28 1.14
+++ libnautilus-extensions/nautilus-file-utilities.h 2000/08/23 04:43:23
@@ -69,6 +69,9 @@
/* Convenience routine to test if a string is a remote URI. */
gboolean nautilus_is_remote_uri (const char *uri);
+/* Transform a path so it safe to pass to the system shell */
+char * nautilus_get_shell_escaped_path (const char *path);
+
/* A version of gnome's gnome_pixmap_file that works for the nautilus prefix.
* Otherwise similar to gnome_pixmap_file in that it checks to see if the file
* exists and returns NULL if it doesn't.
Index: libnautilus-extensions/nautilus-program-choosing.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-extensions/nautilus-program-choosing.c,v
retrieving revision 1.10
diff -U3 -r1.10 nautilus-program-choosing.c
--- libnautilus-extensions/nautilus-program-choosing.c 2000/06/28 22:23:47 1.10
+++ libnautilus-extensions/nautilus-program-choosing.c 2000/08/23 04:43:23
@@ -285,7 +285,6 @@
nautilus_launch_application_parented (application, uri, NULL);
}
-
/**
* nautilus_launch_application_from_command:
*
@@ -300,9 +299,20 @@
nautilus_launch_application_from_command (const char *command_string, const char *uri)
{
char *full_command;
+ char *uri_or_path;
+ char *shell_escaped_path;
if (uri != NULL) {
- full_command = g_strconcat (command_string, " ", uri, " &", NULL);
+ uri_or_path = nautilus_get_local_path_from_uri (uri);
+ if (uri_or_path != NULL) {
+ shell_escaped_path = nautilus_get_shell_escaped_path (uri_or_path);
+ full_command = g_strconcat (command_string, " ", shell_escaped_path, " &", NULL);
+ g_free (uri_or_path);
+ g_free (shell_escaped_path);
+ }
+ else {
+ full_command = g_strconcat (command_string, " ", uri, " &", NULL);
+ }
} else {
full_command = g_strconcat (command_string, " &", NULL);
}
@@ -311,4 +321,3 @@
g_free (full_command);
}
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]