Permalink
Browse files

SERVER-7252 Properly handle empty-string arguments in argv when gener…

…ating a windows command line.
  • Loading branch information...
1 parent 82d5d62 commit ce53447ced1d3c7ad26274dad8099f2bb199c2b0 @andy10gen andy10gen committed Dec 5, 2012
Showing with 28 additions and 3 deletions.
  1. +4 −1 src/mongo/util/text.cpp
  2. +24 −2 src/mongo/util/text_test.cpp
View
@@ -304,7 +304,10 @@ namespace mongo {
// See "Parsing C++ Command-Line Arguments (C++)"
// http://msdn.microsoft.com/en-us/library/windows/desktop/17w5ykft(v=vs.85).aspx
static void quoteForWindowsCommandLine(const std::string& arg, std::ostream& os) {
- if (arg.find_first_of(" \t\"") == std::string::npos) {
+ if (arg.empty()) {
+ os << "\"\"";
+ }
+ else if (arg.find_first_of(" \t\"") == std::string::npos) {
os << arg;
}
else {
@@ -43,8 +43,8 @@ TEST(WindowsCommandLineConstruction, EmptyCommandLine) {
}
TEST(WindowsCommandLineConstruction, NothingToQuote) {
- ASSERT_EQUALS("abc d e",
- constructUtf8WindowsCommandLine(svec("abc", "d", "e", NULL)));
+ ASSERT_EQUALS("abc d \"\" e",
+ constructUtf8WindowsCommandLine(svec("abc", "d", "", "e", NULL)));
}
TEST(WindowsCommandLineConstruction, ThingsToQuote) {
@@ -57,3 +57,25 @@ TEST(WindowsCommandLineConstruction, ThingsToQuote) {
ASSERT_EQUALS("\"\\\\\\\\\\\"\"",
constructUtf8WindowsCommandLine(svec("\\\\\"", NULL)));
}
+
+TEST(WindowsCommandLineConstruction, RegressionSERVER_7252) {
+ ASSERT_EQUALS("mongod \"--serviceName=My Service\" --serviceDescription \"My Service\" "
+ "--serviceDisplayName \"My Service\" --dbpath C:\\mongo\\data\\config "
+ "--port 20001 --logpath C:\\mongo\\logs\\mongo_config.log.txt "
+ "--configsvr --service",
+ constructUtf8WindowsCommandLine(svec("mongod",
+ "--serviceName=My Service",
+ "--serviceDescription",
+ "My Service",
+ "--serviceDisplayName",
+ "My Service",
+ "--dbpath",
+ "C:\\mongo\\data\\config",
+ "--port", "20001",
+ "--logpath",
+ "C:\\mongo\\logs\\mongo_config.log.txt",
+ "--configsvr",
+ "--service",
+ NULL)));
+
+}

0 comments on commit ce53447

Please sign in to comment.