Skip to content

Commit 3bcbba5

Browse files
committed
Fixed #10887 (compile database: include path with space is not handled)
1 parent 92316b0 commit 3bcbba5

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

lib/importproject.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,10 @@ bool ImportProject::importCompileCommands(std::istream &istr)
414414
if (obj["arguments"].is<picojson::array>()) {
415415
for (const picojson::value& arg : obj["arguments"].get<picojson::array>()) {
416416
if (arg.is<std::string>()) {
417-
command += arg.get<std::string>() + " ";
417+
std::string str = arg.get<std::string>();
418+
if (str.find(" ") != std::string::npos)
419+
str = "\"" + str + "\"";
420+
command += str + " ";
418421
}
419422
}
420423
} else {

test/testimportproject.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class TestImportProject : public TestFixture {
5858
TEST_CASE(importCompileCommands7); // linux: "/home/danielm/cppcheck 2"
5959
TEST_CASE(importCompileCommands8); // Windows: "C:\Users\danielm\cppcheck"
6060
TEST_CASE(importCompileCommands9);
61+
TEST_CASE(importCompileCommands10); // #10887: include path with space
6162
TEST_CASE(importCompileCommandsArgumentsSection); // Handle arguments section
6263
TEST_CASE(importCompileCommandsNoCommandSection); // gracefully handles malformed json
6364
TEST_CASE(importCppcheckGuiProject);
@@ -254,13 +255,33 @@ class TestImportProject : public TestFixture {
254255
"powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File d:\\Projekte\\xyz\\firmware\\app\\xyz-lib\\build.ps1 -IAR -COMPILER_PATH \"c:\\Program Files (x86)\\IAR Systems\\Embedded Workbench 9.0\" -CONTROLLER CC1310F128 -LIB LIB_PERMANENT -COMPILER_DEFINES \"CC1310_HFXO_FREQ=24000000 DEBUG\""
255256
],
256257
"directory" : "d:\\Projekte\\xyz\\firmware\\app",
257-
"type" : "PRE"
258+
"type" : "PRE",
259+
"file": "1.c"
258260
}])";
259261
std::istringstream istr(json);
260262
TestImporter importer;
261263
ASSERT_EQUALS(true, importer.importCompileCommands(istr));
262264
}
263265

266+
void importCompileCommands10() const { // #10887
267+
const char json[] =
268+
R"([{
269+
"file": "/home/danielm/cppcheck/1/test folder/1.c" ,
270+
"directory": "",
271+
"arguments": [
272+
"iccavr.exe",
273+
"-I",
274+
"/home/danielm/cppcheck/test folder"
275+
]
276+
}])";
277+
std::istringstream istr(json);
278+
TestImporter importer;
279+
ASSERT_EQUALS(true, importer.importCompileCommands(istr));
280+
ASSERT_EQUALS(1, importer.fileSettings.size());
281+
const ImportProject::FileSettings &fs = importer.fileSettings.front();
282+
ASSERT_EQUALS("/home/danielm/cppcheck/test folder/", fs.includePaths.front());
283+
}
284+
264285
void importCompileCommandsArgumentsSection() const {
265286
const char json[] = "[ { \"directory\": \"/tmp/\","
266287
"\"arguments\": [\"gcc\", \"-c\", \"src.c\"],"

0 commit comments

Comments
 (0)