Ronald Oussoren avatar Ronald Oussoren committed 232d156

This fixes bug #1527397: PythonLauncher runs scripts with the wrong working
directory. It also fixes a bug where PythonLauncher failed to launch scripts
when the scriptname (or the path to the script) contains quotes.

Comments (0)

Files changed (2)


     if (value) with_terminal = [value boolValue];
+- (NSString*)_replaceSingleQuotes: (NSString*)string
+	/* Replace all single-quotes by '"'"', that way shellquoting will
+	 * be correct when the result value is delimited  using single quotes.
+	 */
+	NSArray* components = [string componentsSeparatedByString:@"'"];
+	return [components componentsJoinedByString:@"'\"'\"'"];
 - (NSString *)commandLineForScript: (NSString *)script
     NSString *cur_interp = NULL;
+    NSString* script_dir = NULL;
     char hashbangbuf[1024];
     FILE *fp;
     char *p;
+    script_dir = [script substringToIndex:
+	    [script length]-[[script lastPathComponent] length]];
     if (honourhashbang &&
        (fp=fopen([script cString], "r")) &&
         cur_interp = interpreter;
     return [NSString stringWithFormat:
-        @"\"%@\"%s%s%s%s%s%s %@ \"%@\" %@ %s",
-        cur_interp,
+        @"cd '%@' && '%@'%s%s%s%s%s%s %@ '%@' %@ %s",
+    	[self _replaceSingleQuotes:script_dir],
+        [self _replaceSingleQuotes:cur_interp],
         debug?" -d":"",
         verbose?" -v":"",
         inspect?" -i":"",
         nosite?" -S":"",
         tabs?" -t":"",
-        script,
+        [self _replaceSingleQuotes:script],
         with_terminal? "&& echo Exit status: $? && exit 1" : " &"];
 - Bug #1439538: Drop usage of test -e in configure as it is not portable.
+- PythonLauncher now works correctly when the path to the script contains
+  characters that are treated specially by the shell (such as quotes).
+- Bug #1527397: PythonLauncher now launches scripts with the working directory
+  set to the directory that contains the script instead of the user home
+  directory. That latter was an implementation accident and not what users 
+  expect.
 What's New in Python 2.5 beta 2?
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.