mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
0f53bb1cbe
commit
26cad08748
2 changed files with 29 additions and 3 deletions
|
@ -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" : " &"];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue