Skip to content

Commit 6823c82

Browse files
author
Sunil Srivastava
committed
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 llvm-svn: 356193
1 parent de1d5d3 commit 6823c82

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/Support/CommandLine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,13 @@ void cl::TokenizeWindowsCommandLine(StringRef Src, StringSaver &Saver,
874874
// QUOTED state means that it's reading a token quoted by double quotes.
875875
if (State == QUOTED) {
876876
if (C == '"') {
877+
if (I < (E - 1) && Src[I + 1] == '"') {
878+
// Consecutive double-quotes inside a quoted string implies one
879+
// double-quote.
880+
Token.push_back('"');
881+
I = I + 1;
882+
continue;
883+
}
877884
State = UNQUOTED;
878885
continue;
879886
}

llvm/unittests/Support/CommandLineTest.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ TEST(CommandLineTest, TokenizeGNUCommandLine) {
185185
array_lengthof(Output));
186186
}
187187

188-
TEST(CommandLineTest, TokenizeWindowsCommandLine) {
188+
TEST(CommandLineTest, TokenizeWindowsCommandLine1) {
189189
const char Input[] = "a\\b c\\\\d e\\\\\"f g\" h\\\"i j\\\\\\\"k \"lmn\" o pqr "
190190
"\"st \\\"u\" \\v";
191191
const char *const Output[] = { "a\\b", "c\\\\d", "e\\f g", "h\"i", "j\\\"k",
@@ -194,6 +194,13 @@ TEST(CommandLineTest, TokenizeWindowsCommandLine) {
194194
array_lengthof(Output));
195195
}
196196

197+
TEST(CommandLineTest, TokenizeWindowsCommandLine2) {
198+
const char Input[] = "clang -c -DFOO=\"\"\"ABC\"\"\" x.cpp";
199+
const char *const Output[] = { "clang", "-c", "-DFOO=\"ABC\"", "x.cpp"};
200+
testCommandLineTokenizer(cl::TokenizeWindowsCommandLine, Input, Output,
201+
array_lengthof(Output));
202+
}
203+
197204
TEST(CommandLineTest, TokenizeConfigFile1) {
198205
const char *Input = "\\";
199206
const char *const Output[] = { "\\" };

0 commit comments

Comments
 (0)