diff options
-rw-r--r-- | win32/process.c | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/win32/process.c b/win32/process.c index e93efa103..228b0b30e 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -116,28 +116,12 @@ parse_interpreter(const char *cmd, interp_t *interp) | |||
116 | char * | 116 | char * |
117 | quote_arg(const char *arg) | 117 | quote_arg(const char *arg) |
118 | { | 118 | { |
119 | int force_quotes = 0; | ||
120 | char *r = xmalloc(2 * strlen(arg) + 3); // max-esc, enclosing DQ, \0 | 119 | char *r = xmalloc(2 * strlen(arg) + 3); // max-esc, enclosing DQ, \0 |
121 | char *d = r; | 120 | char *d = r; |
122 | int nbs = 0; // n consecutive BS right before current char | 121 | int nbs = 0; // n consecutive BS right before current char |
123 | const char *p = arg; | ||
124 | 122 | ||
125 | /* empty arguments must be quoted */ | 123 | /* empty arguments and those containing tab/space must be quoted */ |
126 | if (!*p) { | 124 | if (!*arg || strpbrk(arg, " \t")) { |
127 | force_quotes = 1; | ||
128 | } | ||
129 | |||
130 | while (*p) { | ||
131 | if (isspace(*p)) { | ||
132 | /* arguments containing whitespace must be quoted */ | ||
133 | force_quotes = 1; | ||
134 | break; | ||
135 | } | ||
136 | p++; | ||
137 | } | ||
138 | |||
139 | /* insert double quotes and backslashes where necessary */ | ||
140 | if (force_quotes) { | ||
141 | *d++ = '"'; | 125 | *d++ = '"'; |
142 | } | 126 | } |
143 | 127 | ||
@@ -156,7 +140,7 @@ quote_arg(const char *arg) | |||
156 | *d++ = *arg++; | 140 | *d++ = *arg++; |
157 | } | 141 | } |
158 | 142 | ||
159 | if (force_quotes) { | 143 | if (*r == '"') { |
160 | while (nbs--) // double consecutive-BS before the closing DQ | 144 | while (nbs--) // double consecutive-BS before the closing DQ |
161 | *d++ = '\\'; | 145 | *d++ = '\\'; |
162 | *d++ = '"'; | 146 | *d++ = '"'; |