From 239bba0059e5c8284c7f21e2b65b0467b20c6bd7 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 5 Oct 2012 11:18:05 +0100 Subject: Revised quoting of command line arguments for WIN32 * We only need to quote an argument if it contains whitespace. * There's no point in quoting ? or * because Windows still expands them. Anyhow, if the command line comes from a BusyBox shell it will usually have handled the globbing, so we should turn off Windows globbing for any wildcard that has made it through the shell without expansion. This means that BusyBox commands run from cmd.exe won't do wildcard expansion, though. * Backslashes only need to be doubled if they occur immediately before double quotes. * Double quotes need to be escaped with a backslash. --- win32/process.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'win32') diff --git a/win32/process.c b/win32/process.c index 53ad44a42..59bc5b4a0 100644 --- a/win32/process.c +++ b/win32/process.c @@ -117,7 +117,7 @@ quote_arg(const char *arg) const char *p = arg; if (!*p) force_quotes = 1; while (*p) { - if (isspace(*p) || *p == '*' || *p == '?' || *p == '{' || *p == '\'') + if (isspace(*p)) force_quotes = 1; else if (*p == '"') n++; @@ -130,8 +130,6 @@ quote_arg(const char *arg) } if (*p == '"') n += count*2 + 1; - else - n += count; continue; } len++; @@ -142,7 +140,8 @@ quote_arg(const char *arg) /* insert \ where necessary */ d = q = xmalloc(len+n+3); - *d++ = '"'; + if (force_quotes) + *d++ = '"'; while (*arg) { if (*arg == '"') *d++ = '\\'; @@ -152,15 +151,16 @@ quote_arg(const char *arg) count++; *d++ = *arg++; } - while (count-- > 0) - *d++ = '\\'; if (*arg == '"') { + while (count-- > 0) + *d++ = '\\'; *d++ = '\\'; } } *d++ = *arg++; } - *d++ = '"'; + if (force_quotes) + *d++ = '"'; *d++ = 0; return q; } -- cgit v1.2.3-55-g6feb