Correct the escaping of arguments passed through on windows

This commit is contained in:
Martin Storsjö committed 2018-10-10 23:33:18 +03:00
1 parent b9543f23b9
commit fb26be33a1
1 file changed
+13 -1
+13 -1
View File
@@ -53,10 +53,22 @@ static TCHAR *escape(const TCHAR *str) {
int i;
*ptr++ = '"';
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++ = 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++ = '\0';
return out;