1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* process.c (rb_proc_exec): strip trailing spaces. [ruby-dev:24143]

* win32/win32.c (CreateChild): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2004-08-27 01:14:30 +00:00
parent 9b6bafef38
commit e8d486e119
3 changed files with 44 additions and 9 deletions

View file

@ -1,3 +1,9 @@
Fri Aug 27 10:14:21 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* process.c (rb_proc_exec): strip trailing spaces. [ruby-dev:24143]
* win32/win32.c (CreateChild): ditto.
Thu Aug 26 04:38:29 2004 Dave Thomas <dave@pragprog.com> Thu Aug 26 04:38:29 2004 Dave Thomas <dave@pragprog.com>
* eval.c (return_jump): Minor typo in error message. Now reads * eval.c (return_jump): Minor typo in error message. Now reads

View file

@ -1027,8 +1027,17 @@ rb_proc_exec(str)
after_exec(); after_exec();
#else #else
for (s=str; *s; s++) { for (s=str; *s; s++) {
if (ISSPACE(*s)) {
const char *p, *nl = NULL;
for (p = s; ISSPACE(*p); p++) {
if (*p == '\n') nl = p;
}
if (!*p) break;
if (nl) goto via_shell;
}
if (*s != ' ' && !ISALPHA(*s) && strchr("*?{}[]<>()~&|\\$;'`\"\n",*s)) { if (*s != ' ' && !ISALPHA(*s) && strchr("*?{}[]<>()~&|\\$;'`\"\n",*s)) {
int status; int status;
via_shell:
#if defined(MSDOS) #if defined(MSDOS)
before_exec(); before_exec();
status = system(str); status = system(str);
@ -1056,7 +1065,8 @@ rb_proc_exec(str)
} }
a = argv = ALLOCA_N(char*, (s-str)/2+2); a = argv = ALLOCA_N(char*, (s-str)/2+2);
ss = ALLOCA_N(char, s-str+1); ss = ALLOCA_N(char, s-str+1);
strcpy(ss, str); memcpy(ss, str, s-str);
ss[s-str] = '\0';
if (*a++ = strtok(ss, " \t")) { if (*a++ = strtok(ss, " \t")) {
while (t = strtok(NULL, " \t")) { while (t = strtok(NULL, " \t")) {
*a++ = t; *a++ = t;

View file

@ -936,18 +936,29 @@ CreateChild(const char *cmd, const char *prog, SECURITY_ATTRIBUTES *psa,
} }
else { else {
int redir = -1; int redir = -1;
int len = 0;
while (ISSPACE(*cmd)) cmd++;
for (prog = cmd; *prog; prog = CharNext(prog)) {
if (ISSPACE(*prog)) {
len = prog - cmd;
do ++prog; while (ISSPACE(*prog));
if (!*prog) break;
}
else {
len = 0;
}
}
if (!len) len = strlen(cmd);
if ((shell = getenv("RUBYSHELL")) && (redir = has_redirection(cmd))) { if ((shell = getenv("RUBYSHELL")) && (redir = has_redirection(cmd))) {
char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) + char *tmp = ALLOCA_N(char, strlen(shell) + len + sizeof(" -c ") + 2);
sizeof (" -c ") + 2); sprintf(tmp, "%s -c \"%.*s\"", shell, len, cmd);
sprintf(tmp, "%s -c \"%s\"", shell, cmd);
cmd = tmp; cmd = tmp;
} }
else if ((shell = getenv("COMSPEC")) && else if ((shell = getenv("COMSPEC")) &&
((redir < 0 ? has_redirection(cmd) : redir) || ((redir < 0 ? has_redirection(cmd) : redir) ||
isInternalCmd(cmd, shell))) { isInternalCmd(cmd, shell))) {
char *tmp = ALLOCA_N(char, strlen(shell) + strlen(cmd) + char *tmp = ALLOCA_N(char, strlen(shell) + len + sizeof(" /c "));
sizeof (" /c ")); sprintf(tmp, "%s /c %.*s", shell, len, cmd);
sprintf(tmp, "%s /c %s", shell, cmd);
cmd = tmp; cmd = tmp;
} }
else { else {
@ -958,9 +969,17 @@ CreateChild(const char *cmd, const char *prog, SECURITY_ATTRIBUTES *psa,
p = dln_find_exe(cmd, NULL); p = dln_find_exe(cmd, NULL);
break; break;
} }
if (strchr(".:*?\"/\\", *prog)) break; if (strchr(".:*?\"/\\", *prog)) {
if (cmd[len]) {
char *tmp = ALLOCA_N(char, len + 1);
memcpy(tmp, cmd, len);
tmp[len] = 0;
cmd = tmp;
}
break;
}
if (ISSPACE(*prog) || strchr("<>|", *prog)) { if (ISSPACE(*prog) || strchr("<>|", *prog)) {
int len = prog - cmd; len = prog - cmd;
p = ALLOCA_N(char, len + 1); p = ALLOCA_N(char, len + 1);
memcpy(p, cmd, len); memcpy(p, cmd, len);
p[len] = 0; p[len] = 0;