From: "pcai (Peter Cai) via ruby-core" Date: 2023-11-13T20:35:27+00:00 Subject: [ruby-core:115377] [Ruby master Bug#11142] Command line argument parser on windows handles double quotes inconsistently. Issue #11142 has been updated by pcai (Peter Cai). Is there a reason the windows parsing doesn't match the linux behavior?: ``` vscode ��� /workspaces/ruby (master) $ ruby -e "puts ARGV" "foo""bar" foobar vscode ��� /workspaces/ruby (master) $ ruby -e "puts ARGV" "foo"" bar" foo bar ``` And if so, can someone clarify if "treat two double quotes as a literal double quote" is correct? I think the referenced code block reads as: ``` case '\"': if (!quote) quote = *ptr; else if (quote == *ptr) quote = '\0'; ptr++; break; ``` Note that `quote` is initially '\0' and therefore it seems that upon encountering a second double quote, `if (quote == *ptr)` will always be true, so it seems gratuitous? ---------------------------------------- Bug #11142: Command line argument parser on windows handles double quotes inconsistently. https://bugs.ruby-lang.org/issues/11142#change-105312 * Author: ksubrama (Kartik Cating-Subramanian) * Status: Open * Priority: Normal * Assignee: usa (Usaku NAKAMURA) * ruby -v: ruby 2.1.5p273 (2014-11-13 revision 48405) [x64-mingw32] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- 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. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/