Correct the escaping of arguments passed through on windows
This commit is contained in:
1 parent
b9543f23b9
commit
fb26be33a1
1 file changed
+13
-1
@@ -53,10 +53,22 @@ static TCHAR *escape(const TCHAR *str) {
|
|||||||
int i;
|
int i;
|
||||||
*ptr++ = '"';
|
*ptr++ = '"';
|
||||||
for (i = 0; str[i]; i++) {
|
for (i = 0; str[i]; i++) {
|
||||||
if (str[i] == '"')
|
if (str[i] == '"') {
|
||||||
|
int j = i - 1;
|
||||||
|
// Before all double quotes, backslashes need to be escaped, but
|
||||||
|
// not elsewhere.
|
||||||
|
while (j >= 0 && str[j--] == '\\')
|
||||||
|
*ptr++ = '\\';
|
||||||
|
// Escape the next double quote.
|
||||||
*ptr++ = '\\';
|
*ptr++ = '\\';
|
||||||
|
}
|
||||||
*ptr++ = str[i];
|
*ptr++ = str[i];
|
||||||
}
|
}
|
||||||
|
// Any final backslashes, before the quote around the whole argument,
|
||||||
|
// need to be doubled.
|
||||||
|
int j = i - 1;
|
||||||
|
while (j >= 0 && str[j--] == '\\')
|
||||||
|
*ptr++ = '\\';
|
||||||
*ptr++ = '"';
|
*ptr++ = '"';
|
||||||
*ptr++ = '\0';
|
*ptr++ = '\0';
|
||||||
return out;
|
return out;
|
||||||
|
|||||||
Reference in new issue
Block a user