Handle consecutive-double-quotes in Windows argument parsing
Windows command line argument processing treats consecutive double quotes
as a single double-quote. This patch implements this functionality.
Differential Revision: https://reviews.llvm.org/D58662
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356193 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp
index 39991a8..c1193f9 100644
--- a/lib/Support/CommandLine.cpp
+++ b/lib/Support/CommandLine.cpp
@@ -874,6 +874,13 @@
// QUOTED state means that it's reading a token quoted by double quotes.
if (State == QUOTED) {
if (C == '"') {
+ if (I < (E - 1) && Src[I + 1] == '"') {
+ // Consecutive double-quotes inside a quoted string implies one
+ // double-quote.
+ Token.push_back('"');
+ I = I + 1;
+ continue;
+ }
State = UNQUOTED;
continue;
}
diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp
index 4bfa8a3..a7aee41 100644
--- a/unittests/Support/CommandLineTest.cpp
+++ b/unittests/Support/CommandLineTest.cpp
@@ -185,7 +185,7 @@
array_lengthof(Output));
}
-TEST(CommandLineTest, TokenizeWindowsCommandLine) {
+TEST(CommandLineTest, TokenizeWindowsCommandLine1) {
const char Input[] = "a\\b c\\\\d e\\\\\"f g\" h\\\"i j\\\\\\\"k \"lmn\" o pqr "
"\"st \\\"u\" \\v";
const char *const Output[] = { "a\\b", "c\\\\d", "e\\f g", "h\"i", "j\\\"k",
@@ -194,6 +194,13 @@
array_lengthof(Output));
}
+TEST(CommandLineTest, TokenizeWindowsCommandLine2) {
+ const char Input[] = "clang -c -DFOO=\"\"\"ABC\"\"\" x.cpp";
+ const char *const Output[] = { "clang", "-c", "-DFOO=\"ABC\"", "x.cpp"};
+ testCommandLineTokenizer(cl::TokenizeWindowsCommandLine, Input, Output,
+ array_lengthof(Output));
+}
+
TEST(CommandLineTest, TokenizeConfigFile1) {
const char *Input = "\\";
const char *const Output[] = { "\\" };