Bug #2016: Windows (win32.c) command line argument parsing bug
http://redmine.ruby-lang.org/issues/show/2016

Author: David Deley
Status: Open, Priority: Normal
ruby -v: 1.9.1

Fix:
file: \win32\win32.c
routine: rb_w32_cmdvector
line:
memcpy(p - ((slashes + 1) >> 1), p + (~slashes & 1),
   base + len - p);

add 1 to the length so we include the trailing zero:
memcpy(p - ((slashes + 1) >> 1), p + (~slashes & 1),
   base + len + 1 - p);
              ^^^

PROBLEM DESCRIPTION:
INCORRECT PARSING OF COMMAND LINE PARAMETERS
To Reproduce:
#simple show parameters program ShowParams.rb:
ARGV.each do|a|
  puts "Argument: #{a}"
end

Try it with this command line:
> ShowParams.rb hello\\\" goodbye friday
Argument: hello\"\goodbye
Argument: goodbye
Argument: friday

(not sure where to report this as win32.c isn't a part of the Ruby core SVN, though it is in ruby-1.9.1-p129-i386-mswin32.zip)

Appears routine is trying to reproduce the Microsoft Windows C/C++ Command Line Parsing Rules. For more see my essay "How Command Line Parameters Are Parsed:How to properly escape the special characters in your command line parameters" at http://www.autohotkey.net/~deleyd/parameters/parameters.htm


----------------------------------------
http://redmine.ruby-lang.org