From e01be5899427b90d68d22e1a99cfb64bd24652b3 Mon Sep 17 00:00:00 2001 From: Mark Striemer Date: Fri, 29 May 2020 18:41:03 +0000 Subject: [PATCH] Bug 1632277 - Part 2: Remove assembleSingleArgument helper r=tkikuchi Differential Revision: https://phabricator.services.mozilla.com/D75205 --- toolkit/xre/AssembleCmdLine.h | 92 ------------------- .../test/gtest/TestAssembleCommandLineWin.cpp | 14 --- 2 files changed, 106 deletions(-) diff --git a/toolkit/xre/AssembleCmdLine.h b/toolkit/xre/AssembleCmdLine.h index c8e9b786db58..85ff9a7d4823 100644 --- a/toolkit/xre/AssembleCmdLine.h +++ b/toolkit/xre/AssembleCmdLine.h @@ -129,98 +129,6 @@ inline int assembleCmdLine(const char* const* aArgv, wchar_t** aWideCmdLine, return 0; } -# ifdef MOZILLA_INTERNAL_API -inline UniquePtr assembleSingleArgument(const nsString& aArg) { - static_assert(sizeof(char16_t) == sizeof(wchar_t), - "char16_t and wchar_t sizes differ"); - - /* - * \ and " need to be escaped by a \. In the worst case, - * every character is a \ or ", so the string of length - * may double. If we quote an argument, that needs two ". - * Finally, we need a space between arguments, and - * a null byte at the end of command line. - */ - int cmdLineSize = 2 * aArg.Length() /* \ and " need to be escaped */ - + 2 /* we quote every argument */ - + 1; /* space in between, or final null */ - - auto assembledArg = MakeUnique(cmdLineSize); - if (!assembledArg) { - return nullptr; - } - - /* If the argument contains white space, it needs to be quoted. */ - int argNeedQuotes = 0; - if (aArg.FindCharInSet(u" \f\n\r\t\v") != kNotFound) { - argNeedQuotes = 1; - } - - wchar_t* p = assembledArg.get(); - - if (argNeedQuotes) { - *p++ = '"'; - } - - const char16_t* q = aArg.get(); - - int numBackslashes = 0; - while (*q) { - if (*q == '\\') { - numBackslashes++; - q++; - } else if (*q == '"') { - if (numBackslashes) { - /* - * Double the backslashes since they are followed - * by a quote - */ - for (int i = 0; i < 2 * numBackslashes; i++) { - *p++ = '\\'; - } - numBackslashes = 0; - } - /* To escape the quote */ - *p++ = '\\'; - *p++ = *q++; - } else { - if (numBackslashes) { - /* - * Backslashes are not followed by a quote, so - * don't need to double the backslashes. - */ - for (int i = 0; i < numBackslashes; i++) { - *p++ = '\\'; - } - numBackslashes = 0; - } - *p++ = *q++; - } - } - - /* Now we are at the end of this argument */ - if (numBackslashes) { - /* - * Double the backslashes if we have a quote string - * delimiter at the end. - */ - if (argNeedQuotes) { - numBackslashes *= 2; - } - for (int i = 0; i < numBackslashes; i++) { - *p++ = '\\'; - } - } - if (argNeedQuotes) { - *p++ = '"'; - } - - *p = '\0'; - - return assembledArg; -} -# endif // MOZILLA_INTERNAL_API - } // namespace mozilla #endif // defined(XP_WIN) diff --git a/toolkit/xre/test/gtest/TestAssembleCommandLineWin.cpp b/toolkit/xre/test/gtest/TestAssembleCommandLineWin.cpp index 99a2545bd220..7f6791f73d7a 100644 --- a/toolkit/xre/test/gtest/TestAssembleCommandLineWin.cpp +++ b/toolkit/xre/test/gtest/TestAssembleCommandLineWin.cpp @@ -80,17 +80,3 @@ TEST(AssembleCommandLineWin, assembleCmdLine) EXPECT_STREQ(assembled.get(), testCase.mExpected); } } - -TEST(AssembleCommandLineWin, assembleSingleArgument) -{ - for (const auto& testCase : testCases) { - if (testCase.mArgs[1]) { - // Skip a case having more than one argument. - continue; - } - - auto assembled = - assembleSingleArgument(NS_ConvertUTF8toUTF16(testCase.mArgs[0])); - EXPECT_STREQ(assembled.get(), testCase.mExpected); - } -}