diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 91aa93e41..064865756 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -248,20 +248,16 @@ void ImportProject::importCompileCommands(std::istream &istr) } if (F=='D') { std::string defval; - bool escape = false; - while (pos < command.size() && command[pos] != ' ') { - if (command[pos] != '\\') { - defval += command[pos]; - escape = false; + bool str = false; + while (pos < command.size() && (str || command[pos] != ' ')) { + if (command.compare(pos, 4, "\\\\\\\"") == 0) { + defval += '\"'; + str = !str; + pos += 4; } else { - if (escape) { - defval += '\\'; - escape = false; - } else { - escape = true; - } + defval += command[pos]; + pos++; } - pos++; } fs.defines += fval; if (!defval.empty()) diff --git a/test/testimportproject.cpp b/test/testimportproject.cpp index b41185ddd..efc8f22e1 100644 --- a/test/testimportproject.cpp +++ b/test/testimportproject.cpp @@ -94,13 +94,13 @@ private: void importCompileCommands() const { const char json[] = "[ { \"directory\": \"/tmp\"," - "\"command\": \"gcc -I/tmp -DTEST1 -DTEST2=2 -DTEST3=\\\"\\\\\\\"3\\\\\\\"\\\" -o /tmp/src.o -c /tmp/src.c\"," + "\"command\": \"gcc -I/tmp -DCFGDIR=\\\\\\\"/usr/local/share/Cppcheck\\\\\\\" -DTEST1 -DTEST2=2 -o /tmp/src.o -c /tmp/src.c\"," "\"file\": \"/tmp/src.c\" } ]"; std::istringstream istr(json); TestImporter importer; importer.importCompileCommands(istr); ASSERT_EQUALS(1, importer.fileSettings.size()); - ASSERT_EQUALS("TEST1=1;TEST2=2;TEST3=\"\\\"3\\\"\"", importer.fileSettings.begin()->defines); + ASSERT_EQUALS("CFGDIR=\"/usr/local/share/Cppcheck\";TEST1=1;TEST2=2", importer.fileSettings.begin()->defines); } };