Skip to content

Commit 143f2c1

Browse files
committed
Properly escape arguments that include double quotes
1 parent 83437d8 commit 143f2c1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

config.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,18 @@ std::string Config::command() const
9595

9696
cmd += "\"" + m_cppcheck + "\"";
9797

98-
for (const auto &arg : m_args)
99-
cmd += " \"" + arg + "\"";
98+
for (const auto &arg : m_args) {
99+
// If arg contains double quotes, escape them
100+
std::string escapedArg = arg;
101+
size_t pos = 0;
102+
while ((pos = escapedArg.find("\"", pos)) != std::string::npos) {
103+
escapedArg.replace(pos, 1, "\\\"");
104+
pos += 2;
105+
}
106+
cmd += " \"" + escapedArg + "\"";
107+
108+
}
109+
100110

101111
if (!m_projectFilePath.empty()) {
102112
cmd += " \"--project=" + m_projectFilePath.string() + "\" \"--file-filter=" + m_filename.string() + "\"";

0 commit comments

Comments
 (0)