Bug #2016
closedWindows (win32.c) command line argument parsing bug
Description
=begin
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
=end
Updated by usa (Usaku NAKAMURA) about 16 years ago
- Assignee set to usa (Usaku NAKAMURA)
=begin
=end
Updated by usa (Usaku NAKAMURA) about 16 years ago
- Status changed from Open to Feedback
=begin
cannot reproduce with any version of ruby from current svn branches.
I doubt that your registry setting of .rb relationship in the regisitry is wrong.
If so, tt's not ruby's matter.
=end
Updated by usa (Usaku NAKAMURA) about 16 years ago
- Priority changed from Normal to 3
=begin
=end
Updated by nobu (Nobuyoshi Nakada) about 16 years ago
=begin
Show the result of following command:
for /f "tokens=2 delims==" %I in ('assoc .rb') do @ftype %I
=end
Updated by rogerdpack (Roger Pack) about 16 years ago
=begin
This might be related (these commands work with 1.9, but not 1.8 for me [mswin/mingw])
C:\dev\digitalarchive_trunk>ruby -e " "3" " """
-e:1: unterminated string meets end of file
C:\dev\digitalarchive_trunk>ruby -e " "3" "
-e:1: unterminated string meets end of file
-r
=end
Updated by vo.x (Vit Ondruch) about 16 years ago
=begin
Since Ruby 1.9.2 should support wide characters arguments, I would suggest to replace call of GetCommandLine by GetCommandLineW. Then, it is possible to use CommandLineToArgvW API function, which should parse the command line by standard way.
=end
Updated by usa (Usaku NAKAMURA) about 16 years ago
=begin
With "the standard way", we cannot handle single quote and special wildcard characters such as **'', []'' and ``{}''.
Hey everyone, do you want to move to "the standard way" ?
=end
Updated by vo.x (Vit Ondruch) about 16 years ago
=begin
Why it should be problem when these characters will be properly escaped if needed?
=end
Updated by vvs (Vladimir Sizikov) about 16 years ago
=begin
In JRuby world, we don't do that additional special handling of arguments on Windows, and people keep asking about non-working single-quotes and it is confusing, when jruby -e "puts 5" works, but jruby -e 'puts 5 ' doesn't work on Windows. So it seems to me that MRI does the right thing adding that extra-processing of the arguments so that the very same command line would work on Unixes and Windows...
=end
Updated by nobu (Nobuyoshi Nakada) over 15 years ago
- Status changed from Feedback to Rejected
=begin
=end