aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Ninja.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/Ninja.cpp b/src/Ninja.cpp
index 09df2c1..3b3356b 100644
--- a/src/Ninja.cpp
+++ b/src/Ninja.cpp
@@ -3,6 +3,36 @@
namespace ninja
{
+#if defined(_WIN32) || defined(_WIN64)
+ static std::string escape_arg(const std::string &arg) {
+ std::string escaped = "\"";
+ for(char c : arg) {
+ if(c == '"') {
+ escaped += "\"\"";
+ } else {
+ escaped += c;
+ }
+ }
+ escaped += "\"";
+ return escaped;
+ }
+#else
+ static std::string escape_arg(const std::string &arg) {
+ std::string escaped = "\"";
+ for(char c : arg) {
+ if(c == '"') {
+ escaped += "\\\"";
+ } else if(c == '\\') {
+ escaped += "\\\\";
+ } else {
+ escaped += c;
+ }
+ }
+ escaped += "\"";
+ return escaped;
+ }
+#endif
+
static std::string joinArgs(const std::vector<NinjaArg> &args)
{
std::string result;
@@ -19,7 +49,7 @@ namespace ninja
{
case NinjaArg::Type::VALUE:
{
- result += '\"' + arg.arg + '\"';
+ result += escape_arg(arg.arg);
break;
}
case NinjaArg::Type::VARIABLE: