aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Dmitry Lomov <dslomov@google.com>2016-02-03 19:35:42 +0000
committerGravatar David Chen <dzc@google.com>2016-02-03 22:06:59 +0000
commitb5ff50b7596d7ab92c9bf8e656da20e10ddd861a (patch)
tree8574730b4213dc6beff6ed25722b4c250fb39127 /src
parente711f816880aa292bd452ae46ddf3d8b2c776681 (diff)
Quote spaces and quotes in Windows command line.
-- MOS_MIGRATED_REVID=113764325
Diffstat (limited to 'src')
-rw-r--r--src/main/cpp/blaze_util_mingw.cc29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/main/cpp/blaze_util_mingw.cc b/src/main/cpp/blaze_util_mingw.cc
index 3cf33946cb..d9064d148f 100644
--- a/src/main/cpp/blaze_util_mingw.cc
+++ b/src/main/cpp/blaze_util_mingw.cc
@@ -111,6 +111,19 @@ string GetDefaultHostJavabase() {
return javahome;
}
+namespace {
+void ReplaceAll(
+ std::string* s, const std::string& pattern, const std::string with) {
+ size_t pos = 0;
+ while (true) {
+ size_t pos = s->find(pattern, pos);
+ if (pos == std::string::npos) return;
+ *s = s->replace(pos, pattern.length(), with);
+ pos += with.length();
+ }
+}
+} // namespace
+
// Replace the current process with the given program in the given working
// directory, using the given argument vector.
// This function does not return on success.
@@ -147,7 +160,21 @@ void ExecuteProgram(const string& exe, const vector<string>& args_vector) {
} else {
cmdline.append(" ");
}
- cmdline.append(s);
+
+ string arg = s;
+ // Quote quotes.
+ if (s.find("\"") != string::npos) {
+ ReplaceAll(&arg, "\"", "\\\"");
+ }
+
+ // Quotize spaces.
+ if (arg.find(" ") != string::npos) {
+ cmdline.append("\"");
+ cmdline.append(arg);
+ cmdline.append("\"");
+ } else {
+ cmdline.append(arg);
+ }
}
// Copy command line into a mutable buffer.