Skip to content

Commit

Permalink
* win32/win32.c (rb_w32_spawn): use shell if a commandline contain
Browse files Browse the repository at this point in the history
  double-quote character.
* win32/win32.c (is_internal_cmd): similar, use shell if a commandline
  contain caret character.

* test/ruby/test_system.rb (TestSystem#test_system_at): fix
  wrong test case. if system() invoke a command by using shell,
  system() never return nil. Also, "" quotation must not appear
  twice in a command line.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
kosaki committed Feb 28, 2011
1 parent 2755f11 commit 4a57c5e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Mon Feb 28 22:48:56 2011 KOSAKI Motohiro <[email protected]>

* win32/win32.c (rb_w32_spawn): use shell if a commandline contain
double-quote character.
* win32/win32.c (is_internal_cmd): similar, use shell if a commandline
contain caret character.

* test/ruby/test_system.rb (TestSystem#test_system_at): fix
wrong test case. if system() invoke a command by using shell,
system() never return nil. Also, "" quotation must not appear
twice in a command line.

Mon Feb 28 17:36:57 2011 Tanaka Akira <[email protected]>

* ext/openssl/ossl_pkcs7.c: parenthesize macro arguments.
Expand Down
9 changes: 4 additions & 5 deletions test/ruby/test_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ def test_system_at
assert_equal("@@foo\n", `"echo" @@foo`, bug4396);
assert_equal("@@foo\n", `"@@echo" @@foo`, bug4396);
assert_equal("@@foo\n", `"@@echo @@foo"`, bug4396);
assert_equal('"@foo"\n', `"echo" "@foo"`, bug4396);

# ^ + @ + built-in
assert_equal(nil, system('^@echo foo'), bug4396);
assert_equal(nil, system('"^@echo foo"'), bug4396);
assert_equal(false, system('^@echo foo'), bug4396);
assert_equal(false, system('"^@echo foo"'), bug4396);
assert_equal("@foo\n", `echo ^@foo`);

Dir.mktmpdir("ruby_script_tmp") {|tmpdir|
Expand All @@ -120,8 +119,8 @@ def test_system_at
assert_match(/\Abar\nbaz\n?\z/, `@@findstr "ba" #{tmpfilename.gsub("/", "\\")}`, bug4393);

# "" + @ + non built-in
assert_match(/\Abar\nbaz\n?\z/, `"@@findstr" "ba" #{tmpfilename.gsub("/", "\\")}`, bug4396);
assert_match(/\A@foo\n?\z/, `"@@findstr" "@foo" #{tmpfilename.gsub("/", "\\")}`, bug4396);
assert_match(/\Abar\nbaz\n?\z/, `"@@findstr ba" #{tmpfilename.gsub("/", "\\")}`, bug4396);
assert_match(/\A@foo\n?\z/, `"@@findstr @foo" #{tmpfilename.gsub("/", "\\")}`, bug4396);
}
end
end
Expand Down
9 changes: 9 additions & 0 deletions win32/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,9 @@ is_internal_cmd(const char *cmd, int nt)
{
char cmdname[9], *b = cmdname, c;

if (strchr(cmd, '^'))
return 1;

do {
if (!(c = *cmd++)) return 0;
} while (isspace(c));
Expand Down Expand Up @@ -1138,6 +1141,12 @@ rb_w32_spawn(int mode, const char *cmd, const char *prog)
sprintf(tmp, "%s -c \"%s\"", shell, cmd);
cmd = tmp;
}
else if ((shell = getenv("COMSPEC")) &&
strchr(cmd, '"')) {
char *tmp = ALLOCV(v, strlen(shell) + strlen(cmd) + sizeof(" /c "));
sprintf(tmp, "%s /c %s", shell, cmd);
cmd = tmp;
}
else if ((shell = getenv("COMSPEC")) &&
(nt = !is_command_com(shell),
(redir < 0 ? has_redirection(cmd) : redir) ||
Expand Down

0 comments on commit 4a57c5e

Please sign in to comment.