[PATCH] Fix parameter passing containing quote/equal to Windows batch command

Daniel Dai daijyc@gmail.com
Mon Jan 20 06:03:00 GMT 2014


We notice one issue when running a Windows batch command inside
cygwin. Here is one example.

Simple batch file:
a.bat:
echo %1

Run it under cygwin:
./a.bat a=b
a

./a.bat "a=b"
a

If we pass additional \"
./a.bat "\"a=b\""
"\"a

There seems no way to pass a=b into bat.

Attach quote.patch contains a fix. It does two things:
1. If the parameter contains a equal sign, automatically add quote
(similar to space, tab, new line, quote cygwin already do)
2. If the parameter is already quoted, don't quote again

Patch:
Index: cygwin/winf.cc
==============================
=====================================
RCS file: /cvs/src/src/winsup/cygwin/winf.cc,v
retrieving revision 1.10
diff -u -p -r1.10 winf.cc
--- cygwin/winf.cc      19 Jun 2013 16:00:43 -0000      1.10
+++ cygwin/winf.cc      20 Jan 2014 00:50:15 -0000
@@ -72,11 +72,16 @@ linebuf::fromargv (av& newargv, const ch
     {
       char *p = NULL;
       const char *a;
+      boolean enclosed_with_quote = false;

       a = i ? newargv[i] : (char *) real_path;
       int len = strlen (a);
-      if (len != 0 && !strpbrk (a, " \t\n\r\""))
-       add (a, len);
+      if (len != 0 && a[0] == '\"' && a[len-1] == '\"') {
+        enclosed_with_quote = true;
+      }
+      if (enclosed_with_quote || (len != 0 && !strpbrk (a, " \t\n\r\"="))) {
+        add (a, len);
+      }
       else
        {
          add ("\"", 1);

Thanks,
Daniel



More information about the Cygwin-patches mailing list