Fix quoting for printed file paths
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-win (push) Waiting to run
CodeQL / Analyze (push) Waiting to run

This commit is contained in:
Andrea Mazzoleni 2025-10-27 00:50:21 +01:00
parent 21acc31bf1
commit 8ae0599c64
3 changed files with 538 additions and 157 deletions

View file

@ -45,46 +45,53 @@ static int needs_quote(const WCHAR* arg)
static int argcat(WCHAR* cmd, int size, int pos, const WCHAR* arg)
{
int has_quote;
/* space separator */
if (pos != 0)
charcat(L' ');
if (!needs_quote(arg)) {
has_quote = needs_quote(arg);
if (!has_quote) {
while (*arg)
charcat(*arg++);
return pos;
}
} else {
/* starting quote */
charcat(L'"');
charcat(L'"');
while (*arg) {
int bl = 0;
while (*arg == L'\\') {
++arg;
++bl;
}
while (*arg) {
int bl = 0;
while (*arg == L'\\') {
++arg;
++bl;
if (*arg == 0) {
/* double backslashes before closing quote */
bl = bl * 2;
while (bl--)
charcat(L'\\');
} else if (*arg == '"') {
/* double backslashes + escape the quote */
bl = bl * 2 + 1;
while (bl--)
charcat(L'\\');
charcat(L'"');
++arg;
} else {
/* normal backslashes */
while (bl--)
charcat(L'\\');
charcat(*arg);
++arg;
}
}
if (*arg == 0) {
bl = bl * 2;
while (bl--)
charcat(L'\\');
} else if (*arg == '"') {
bl = bl * 2 + 1;
while (bl--)
charcat(L'\\');
charcat(L'"');
++arg;
} else {
while (bl--)
charcat(L'\\');
charcat(*arg);
++arg;
}
/* ending quote */
charcat(L'"');
}
/* ending quote */
charcat(L'"');
return pos;
}