Browse Source

* patch by Dean Mustakinov to improve commandline quote handling on Windows, resolves #40189

marcoonthegit 2 years ago
parent
commit
e74d89ce62
2 changed files with 32 additions and 5 deletions
  1. 32 5
      rtl/win/syswin.inc
  2. BIN
      tests/utils/dosbox/exitcode.exe

+ 32 - 5
rtl/win/syswin.inc

@@ -223,7 +223,7 @@ var
   buf: array[0..MaxPathLen] of WideChar;
   buf: array[0..MaxPathLen] of WideChar;
   i, len, argvw_size: longint;
   i, len, argvw_size: longint;
   s: RawByteString;
   s: RawByteString;
-  quote: boolean;
+  quote: char;
 begin
 begin
   // Get the unicode command line
   // Get the unicode command line
   CmdLineW:=GetCommandLineW;
   CmdLineW:=GetCommandLineW;
@@ -248,14 +248,14 @@ begin
   Inc(pw, len);
   Inc(pw, len);
   // Parse the command line
   // Parse the command line
   argc:=0;
   argc:=0;
-  quote:=False;
+  quote:=' ';
   while True do
   while True do
     begin
     begin
       c:=CmdLineW^;
       c:=CmdLineW^;
       Inc(CmdLineW);
       Inc(CmdLineW);
       case c of
       case c of
         #0..#32:
         #0..#32:
-          if not quote or (c = #0) then
+          if (quote = ' ') or (c = #0) then
             begin
             begin
               // Are there any chars of an argument?
               // Are there any chars of an argument?
               if argvw[argc] <> pw then
               if argvw[argc] <> pw then
@@ -283,8 +283,35 @@ begin
             end;
             end;
         '"':
         '"':
           begin
           begin
-            quote:=not quote;
-            continue;
+            if quote<>'''' then
+              begin
+                if CmdLineW^<>'"' then
+                  begin
+                    if quote='"' then
+                       quote:=' '
+                     else
+                       quote:='"';
+                     continue;
+                  end
+                else
+                  Inc(CmdLineW);
+              end;
+          end;
+        '''':
+          begin
+            if quote<>'"' then
+              begin
+                if CmdLineW^<>'''' then
+                  begin
+                    if quote='''' then
+                       quote:=' '
+                     else
+                       quote:='''';
+                    continue;
+                  end
+                else
+                  Inc(CmdLineW);
+              end;
           end;
           end;
       end;
       end;
       // Ignore the first argument, it is already copied
       // Ignore the first argument, it is already copied

BIN
tests/utils/dosbox/exitcode.exe