Bug 1853920 - [2/2] quote empty strings in Windows command lines r=win-reviewers,gstoll

Quote empty arguments in command lines. Add appropriate tests.

Differential Revision: https://phabricator.services.mozilla.com/D191128
This commit is contained in:
Ray Kraesig
2023-10-25 19:51:11 +00:00
parent ac8d2004b1
commit 84f30582e7
2 changed files with 15 additions and 2 deletions

View File

@@ -362,8 +362,12 @@ inline size_t CopyArgImpl_(wchar_t* d, const wchar_t* s) {
};
bool hasDoubleQuote = wcschr(s, L'"') != nullptr;
// Only add doublequotes if the string contains a space or a tab
bool addDoubleQuotes = wcspbrk(s, kCommandLineDelimiter) != nullptr;
// Only add doublequotes if...
bool addDoubleQuotes =
// ... the string is empty, or...
*s == '\0' ||
// ... the string contains a space or a tab.
wcspbrk(s, kCommandLineDelimiter) != nullptr;
if (addDoubleQuotes) {
appendChar('"');

View File

@@ -92,3 +92,12 @@ output_24=a:\b "c\アルファ オメガ\d"
input_25=アルファ オメガ
output_25=アルファ オメガ
input_26=arg1 "" arg3
output_26=arg1 "" arg3
input_27=""""
output_27=""""
input_28=""" a """
output_28=""" a """