Skip to content

Commit

Permalink
Win32 argument quoting (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlitz committed Mar 15, 2010
1 parent 9754ebe commit 69d9c0b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 11 additions & 4 deletions lib/rcov/rcovtask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,18 @@ def file_list # :nodoc:

private

# Shell-quote an argument
def shellquote_arg(arg) # :nodoc:
# Shell-quote an argument, by surrounding it in single-quotes, and
# replacing internal single-quotes by '\'' (closing quote,
# backslash-quote, opening quote)
"'"+arg.gsub(/'/, "'\\\\''")+"'"
if File::Separator == "\\" # Win32 - XXX untested
raise ArgumentError.new("Illegal character(s) in argument") if arg =~ /["\000]/m
'"' + arg + '"'
else # POSIX /bin/sh
# Shell-quote an argument, by surrounding it in single-quotes, and
# replacing internal single-quotes by '\'' (closing quote,
# backslash-quote, opening quote)
raise ArgumentError.new("Illegal character(s) in argument") if arg =~ /[\000]/m
"'"+arg.gsub(/'/, "'\\\\''")+"'"
end
end

def shellquote_args(args) # :nodoc:
Expand Down
9 changes: 7 additions & 2 deletions test/rcov_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ def test_opts_posix_shellquoted
t.rcov_opts = [ '--exclude', %q!(\A|/)(test_.*|.*_spec)\.rb\Z! ]
t.rcov_opts += [ '--diff-cmd', %q!O'Brian's Diff Tool! ]
end
assert_equal %q!'-I/path/with spaces/lib' '-Ilib' 'bin/rcov' '--exclude' '(\\A|/)(test_.*|.*_spec)\\.rb\\Z' '--diff-cmd' 'O'\\''Brian'\\''s Diff Tool' '-o' 'coverage' 'foo.rb'!,
t.send(:shellquoted_ruby_args), "shell arguments should be quoted properly for POSIX shells"
if File::Separator == "\\" # Win32 - XXX untested
assert_equal %q!"-I/path/with spaces/lib" "-Ilib" "bin/rcov" "--exclude" "(\\A|/)(test_.*|.*_spec)\\.rb\\Z" "--diff-cmd" "O'Brian's Diff Tool" "-o" "coverage" "foo.rb"!,
t.send(:shellquoted_ruby_args), "shell arguments should be quoted properly for Win32 shell"
else # POSIX /bin/sh
assert_equal %q!'-I/path/with spaces/lib' '-Ilib' 'bin/rcov' '--exclude' '(\\A|/)(test_.*|.*_spec)\\.rb\\Z' '--diff-cmd' 'O'\\''Brian'\\''s Diff Tool' '-o' 'coverage' 'foo.rb'!,
t.send(:shellquoted_ruby_args), "shell arguments should be quoted properly for POSIX shells"
end
ensure
ENV['RCOVPATH'] = saved_rcovpath if saved_rcovpath
ENV['RCOVOPTS'] = saved_rcovopts if saved_rcovopts
Expand Down

0 comments on commit 69d9c0b

Please sign in to comment.