From fd56b3d6f95024cb32043a293f6e56293c22e8cc Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Mon, 24 Aug 2015 00:48:06 +0100
Subject: [PATCH 12/N] dcrt0.cc (globify): Don't quote literal strings
 differently when dos_spec

Reverts 25ba8f306f3099caf8397859019e936b90510e8d. I can't figure out what
the intention was. I'm sure I'll find out soon enough when everything breaks.

This change means that input of:
  '"C:/test.exe SOME_VAR=\"literal quotes\""'

becomes:
  'C:/test.exe SOME_VAR="literal quotes"'

instead of:
  'C:/test.exe SOME_VAR=\literal quotes\'

.. which is at least consistent with the result for:
  '"no_drive_or_colon SOME_VAR=\"literal quotes\""'

The old result of course resulted in the quoted string being split into
two arguments at the space which is clearly not intended.

I *guess* backslashes in dos paths may have been the issue here?
If so I don't care since we should not use them, ever, esp. not at
the expense of sensible forward-slash-containing input.
---
 winsup/cygwin/dcrt0.cc | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index c2da0cb..7ac8bf0 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -235,10 +235,20 @@ globify (char *word, char **&argv, int &argc, int &argvlen)
 	char quote = *s;
 	while (*++s && *s != quote)
 	  {
+	    /* This used to be:
 	    if (dos_spec || *s != '\\')
-	      /* nothing */;
+	      // nothing
 	    else if (s[1] == quote || s[1] == '\\')
 	      s++;
+	    With commit message:
+	       dcrt0.cc (globify): Don't use \ quoting when apparently quoting a DOS path
+	       spec, even within a quoted string.
+	    But that breaks the "literal quotes" part of '"C:/test.exe SOME_VAR=\"literal quotes\""'
+	    giving:    'C:/test.exe SOME_VAR=\literal quotes\' (with \'s between each character)
+	    instead of 'C:/test.exe SOME_VAR="literal quotes"' (with \'s between each character)
+	    */
+	    if (*s == '\\' && (s[1] == quote || s[1] == '\\'))
+	      s++;
 	    *p++ = '\\';
 	    size_t cnt = isascii (*s) ? 1 : mbtowc (NULL, s, MB_CUR_MAX);
 	    if (cnt <= 1 || cnt == (size_t)-1)
-- 
2.31.1

