Bug #11142
openCommand line argument parser on windows handles double quotes inconsistently.
Description
I believe the issue is with https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1671 through 1673.
C:\Users\ksubrama>ruby -e "puts ARGV" "foo""bar"
foo"bar
C:\Users\ksubrama>ruby -e "puts ARGV" "foo"" bar"
foo"
bar
I believe the intent is that if ruby encounters "" inside a " quoted string, then it interprets it as a literal " and doesn't close out the string. If that's the case, then the code should read:
if (quote == L'"' && quote == ptr[1])
ptr++;
else
quote = L'\0';
Otherwise, the string gets closed out anyway and the ptr++ here combined with the ptr++ at the bottom of the switch at line 1685 simply skip over both "" characters while considering the string closed.
As a further test case consider:
C:\Users\ksubrama>ruby -e "puts ARGV" "foo""bar""baz"
foo"barbaz
The parser is now very confused because the first "" closed out the string and the next "" is not interpreted as a literal " but as "open and close and empty string element" and the trailing " just gets dropped.