diff options
author | Ronald Oussoren <ronaldoussoren@mac.com> | 2006-08-01 21:00:57 (GMT) |
---|---|---|
committer | Ronald Oussoren <ronaldoussoren@mac.com> | 2006-08-01 21:00:57 (GMT) |
commit | 26cad08748668fc22b673cdbda99067f0b9016c7 (patch) | |
tree | fc8a629e947a39c107beb0421072f6d1578240b4 /Mac | |
parent | 0f53bb1cbe09886291f880c66220db534d40d6a1 (diff) | |
download | cpython-26cad08748668fc22b673cdbda99067f0b9016c7.zip cpython-26cad08748668fc22b673cdbda99067f0b9016c7.tar.gz cpython-26cad08748668fc22b673cdbda99067f0b9016c7.tar.bz2 |
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.
Diffstat (limited to 'Mac')
-rwxr-xr-x | Mac/PythonLauncher/FileSettings.m | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/Mac/PythonLauncher/FileSettings.m b/Mac/PythonLauncher/FileSettings.m index fc3937b..ba375ba 100755 --- a/Mac/PythonLauncher/FileSettings.m +++ b/Mac/PythonLauncher/FileSettings.m @@ -245,12 +245,26 @@ 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")) && @@ -266,8 +280,9 @@ 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":"", @@ -275,7 +290,7 @@ nosite?" -S":"", tabs?" -t":"", others, - script, + [self _replaceSingleQuotes:script], scriptargs, with_terminal? "&& echo Exit status: $? && exit 1" : " &"]; } |