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

win32.c: use backslash

* win32/win32.c (join_argv): use backslash instead of slash in program
  path, otherwise cannot invoke "./c\u{1ee7}a.exe" for some reason.
  [ruby-core:24309] [Bug #1771]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-06-30 01:59:25 +00:00
parent 637d668bca
commit 5197f451de
3 changed files with 47 additions and 15 deletions

View file

@ -1,4 +1,8 @@
Sun Jun 30 10:59:18 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun Jun 30 10:59:23 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (join_argv): use backslash instead of slash in program
path, otherwise cannot invoke "./c\u{1ee7}a.exe" for some reason.
[ruby-core:24309] [Bug #1771]
* io.c (spawnv, spawn): use UTF-8 spawn family. [Bug #1771] * io.c (spawnv, spawn): use UTF-8 spawn family. [Bug #1771]

View file

@ -1618,7 +1618,7 @@ EOS
[ [
"\u{7d05 7389}", "\u{7d05 7389}",
"zuf\u{00E4}llige_\u{017E}lu\u{0165}ou\u{010D}k\u{00FD}_\u{10D2 10D0 10DB 10D4 10DD 10E0 10D4 10D1}_\u{0440 0430 0437 043B 043E 0433 0430}_\u{548C 65B0 52A0 5761 4EE5 53CA 4E1C}", "zuf\u{00E4}llige_\u{017E}lu\u{0165}ou\u{010D}k\u{00FD}_\u{10D2 10D0 10DB 10D4 10DD 10E0 10D4 10D1}_\u{0440 0430 0437 043B 043E 0433 0430}_\u{548C 65B0 52A0 5761 4EE5 53CA 4E1C}",
# "c\u{1EE7}a", # work with a backslash, but not with a slash, for some reason. "c\u{1EE7}a",
].each do |name| ].each do |name|
msg = "#{bug1771} #{name}" msg = "#{bug1771} #{name}"
exename = "./#{name}.exe" exename = "./#{name}.exe"

View file

@ -980,7 +980,7 @@ rb_w32_get_osfhandle(int fh)
/* License: Ruby's */ /* License: Ruby's */
static int static int
join_argv(char *cmd, char *const *argv, BOOL escape, UINT cp) join_argv(char *cmd, char *const *argv, BOOL escape, UINT cp, int backslash)
{ {
const char *p, *s; const char *p, *s;
char *q, *const *t; char *q, *const *t;
@ -1034,6 +1034,11 @@ join_argv(char *cmd, char *const *argv, BOOL escape, UINT cp)
if (quote) len++; if (quote) len++;
if (q) { if (q) {
memcpy(q, s, n); memcpy(q, s, n);
if (backslash > 0) {
--backslash;
q[n] = 0;
translate_char(q, '/', '\\', cp);
}
q += n; q += n;
if (quote) *q++ = '"'; if (quote) *q++ = '"';
*q++ = ' '; *q++ = ' ';
@ -1205,6 +1210,8 @@ w32_spawn(int mode, const char *cmd, const char *prog, UINT cp)
rb_pid_t ret = -1; rb_pid_t ret = -1;
VALUE v = 0; VALUE v = 0;
VALUE v2 = 0; VALUE v2 = 0;
int sep = 0;
char *cmd_sep = NULL;
if (check_spawn_mode(mode)) return -1; if (check_spawn_mode(mode)) return -1;
@ -1222,8 +1229,11 @@ w32_spawn(int mode, const char *cmd, const char *prog, UINT cp)
int nt; int nt;
while (ISSPACE(*cmd)) cmd++; while (ISSPACE(*cmd)) cmd++;
if ((shell = getenv("RUBYSHELL")) && (redir = has_redirection(cmd, cp))) { if ((shell = getenv("RUBYSHELL")) && (redir = has_redirection(cmd, cp))) {
char *tmp = ALLOCV(v, strlen(shell) + strlen(cmd) + sizeof(" -c ") + 2); size_t shell_len = strlen(shell);
sprintf(tmp, "%s -c \"%s\"", shell, cmd); char *tmp = ALLOCV(v, shell_len + strlen(cmd) + sizeof(" -c ") + 2);
memcpy(tmp, shell, shell_len + 1);
translate_char(tmp, '/', '\\', cp);
sprintf(tmp + shell_len, " -c \"%s\"", cmd);
cmd = tmp; cmd = tmp;
} }
else if ((shell = getenv("COMSPEC")) && else if ((shell = getenv("COMSPEC")) &&
@ -1236,27 +1246,44 @@ w32_spawn(int mode, const char *cmd, const char *prog, UINT cp)
} }
else { else {
int len = 0, quote = (*cmd == '"') ? '"' : (*cmd == '\'') ? '\'' : 0; int len = 0, quote = (*cmd == '"') ? '"' : (*cmd == '\'') ? '\'' : 0;
int slash = 0;
for (prog = cmd + !!quote;; prog = CharNextExA(cp, prog, 0)) { for (prog = cmd + !!quote;; prog = CharNextExA(cp, prog, 0)) {
if (*prog == '/') slash = 1;
if (!*prog) { if (!*prog) {
len = prog - cmd; len = prog - cmd;
if (slash) {
STRNDUPV(p, v2, cmd, len);
cmd = p;
}
shell = cmd; shell = cmd;
break; break;
} }
if ((unsigned char)*prog == quote) { if ((unsigned char)*prog == quote) {
len = prog++ - cmd - 1; len = prog++ - cmd - 1;
STRNDUPV(p, v2, cmd + 1, len); STRNDUPV(p, v2, cmd + 1 - slash, len + (slash ? strlen(prog) + 2 : 0));
if (slash) {
cmd = p++;
sep = *(cmd_sep = &p[len + 1]);
*cmd_sep = '\0';
}
shell = p; shell = p;
break; break;
} }
if (quote) continue; if (quote) continue;
if (ISSPACE(*prog) || strchr("<>|*?\"", *prog)) { if (ISSPACE(*prog) || strchr("<>|*?\"", *prog)) {
len = prog - cmd; len = prog - cmd;
STRNDUPV(p, v2, cmd, len); STRNDUPV(p, v2, cmd, len + (slash ? strlen(prog) : 0));
if (slash) {
cmd = p;
sep = *(cmd_sep = &p[len]);
*cmd_sep = '\0';
}
shell = p; shell = p;
break; break;
} }
} }
shell = dln_find_exe_r(shell, NULL, fbuf, sizeof(fbuf)); shell = dln_find_exe_r(shell, NULL, fbuf, sizeof(fbuf));
if (p && slash) translate_char(p, '/', '\\', cp);
if (!shell) { if (!shell) {
shell = p ? p : cmd; shell = p ? p : cmd;
} }
@ -1285,10 +1312,11 @@ w32_spawn(int mode, const char *cmd, const char *prog, UINT cp)
} }
} }
if (!e && cmd && !(wcmd = mbstr_to_wstr(cp, cmd, -1, NULL))) e = E2BIG;
if (v) ALLOCV_END(v);
if (!e && shell && !(wshell = mbstr_to_wstr(cp, shell, -1, NULL))) e = E2BIG; if (!e && shell && !(wshell = mbstr_to_wstr(cp, shell, -1, NULL))) e = E2BIG;
if (v2) ALLOCV_END(v2); if (v2) ALLOCV_END(v2);
if (cmd_sep) *cmd_sep = sep;
if (!e && cmd && !(wcmd = mbstr_to_wstr(cp, cmd, -1, NULL))) e = E2BIG;
if (v) ALLOCV_END(v);
if (!e) { if (!e) {
ret = child_result(CreateChild(wcmd, wshell, NULL, NULL, NULL, NULL, 0), mode); ret = child_result(CreateChild(wcmd, wshell, NULL, NULL, NULL, NULL, 0), mode);
@ -1355,20 +1383,20 @@ w32_aspawn_flags(int mode, const char *prog, char *const *argv, DWORD flags, UIN
char *progs[2]; char *progs[2];
progs[0] = (char *)prog; progs[0] = (char *)prog;
progs[1] = NULL; progs[1] = NULL;
len = join_argv(NULL, progs, ntcmd, cp); len = join_argv(NULL, progs, ntcmd, cp, 1);
if (c_switch) len += 3; if (c_switch) len += 3;
else ++argv; else ++argv;
if (argv[0]) len += join_argv(NULL, argv, ntcmd, cp); if (argv[0]) len += join_argv(NULL, argv, ntcmd, cp, 0);
cmd = ALLOCV(v, len); cmd = ALLOCV(v, len);
join_argv(cmd, progs, ntcmd, cp); join_argv(cmd, progs, ntcmd, cp, 1);
if (c_switch) strlcat(cmd, " /c", len); if (c_switch) strlcat(cmd, " /c", len);
if (argv[0]) join_argv(cmd + strlcat(cmd, " ", len), argv, ntcmd, cp); if (argv[0]) join_argv(cmd + strlcat(cmd, " ", len), argv, ntcmd, cp, 0);
prog = c_switch ? shell : 0; prog = c_switch ? shell : 0;
} }
else { else {
len = join_argv(NULL, argv, FALSE, cp); len = join_argv(NULL, argv, FALSE, cp, 1);
cmd = ALLOCV(v, len); cmd = ALLOCV(v, len);
join_argv(cmd, argv, FALSE, cp); join_argv(cmd, argv, FALSE, cp, 1);
} }
if (!e && cmd && !(wcmd = mbstr_to_wstr(cp, cmd, -1, NULL))) e = E2BIG; if (!e && cmd && !(wcmd = mbstr_to_wstr(cp, cmd, -1, NULL))) e = E2BIG;