threads / patch / 18512

patchMinGW: Quote arguments for subprocesses that contain a single-quote

Subject: [PATCH] MinGW: Quote arguments for subprocesses that contain a single-quote

## tl;dr

One message between Mar 24, 2009 and Mar 24, 2009. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Johannes Sixt· Mar 24, 2009, 20:43 UTC · lore

Before a process can be spawned by mingw_spawnve, arguments must be surrounded by double-quotes if special characters are present. This is necessary because the startup code of the spawned process will expand arguments that look like glob patterns. "Normal" Windows command line utilities expand only * and ?, but MSYS programs, including bash, are different: They also expand braces, and this has already been taken care of by compat/mingw.c:quote_arg().

But MSYS programs also treat single-quotes in a special way: Arguments between single-quotes are spliced together (with spaces) into a word. With this patch this treatment is avoided by quoting arguments that contain single-quotes.

This lets t4252 pass on Windows.
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 t4252 passes a --directory argument with a single-quote to git-am. As a
 consequence, this argument was spliced into a single word with the
 remaining arguments, including the mbox file name. Following that,
 git-mailsplit was called without a mailbox, upon which it waited for input
 on stdin.
 -- Hannes
 compat/mingw.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to compat/mingw.c +1 −1
diff --git a/compat/mingw.c b/compat/mingw.c
index 171fa85..2839d9d 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -457,7 +457,7 @@ static const char *quote_arg(const char *arg)
 	const char *p = arg;
 	if (!*p) force_quotes = 1;
 	while (*p) {
-		if (isspace(*p) || *p == '*' || *p == '?' || *p == '{')
+		if (isspace(*p) || *p == '*' || *p == '?' || *p == '{' || *p == '\'')
 			force_quotes = 1;
 		else if (*p == '"')
 			n++;
-- 
1.6.2.1.224.g2225f

← back to recent threads