summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorSara Golemon <sara.golemon@mongodb.com>2017-09-14 15:24:18 -0400
committerSara Golemon <sara.golemon@mongodb.com>2017-09-21 11:19:26 -0400
commitf3bf7e7920a51df7100238a55c304ed7cd3aed1f (patch)
treea43a89c9a0f960cea7a2f9ce31c5ecc3243d5131 /src/mongo/shell
parent6c4c5f47b2e3fbf841683448a5e117e86f72c4ef (diff)
downloadmongo-f3bf7e7920a51df7100238a55c304ed7cd3aed1f.tar.gz
SERVER-29921 rewrite URI parser
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/dbshell.cpp14
-rw-r--r--src/mongo/shell/mongo.js3
2 files changed, 11 insertions, 6 deletions
diff --git a/src/mongo/shell/dbshell.cpp b/src/mongo/shell/dbshell.cpp
index fe84178ac2f..051d5726993 100644
--- a/src/mongo/shell/dbshell.cpp
+++ b/src/mongo/shell/dbshell.cpp
@@ -43,6 +43,7 @@
#include "mongo/base/initializer.h"
#include "mongo/base/status.h"
#include "mongo/client/dbclientinterface.h"
+#include "mongo/client/mongo_uri.h"
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/db/client.h"
#include "mongo/db/log_process_details.h"
@@ -241,8 +242,8 @@ string getURIFromArgs(const std::string& url, const std::string& host, const std
}
// If there's a slash in the host field, then it's the replica set name, not a database name
stringstream ss;
- ss << "mongodb://" << host.substr(slashPos + 1)
- << "/?replicaSet=" << host.substr(0, slashPos);
+ ss << "mongodb://" << uriEncode(host.substr(slashPos + 1))
+ << "/?replicaSet=" << uriEncode(host.substr(0, slashPos));
return ss.str();
}
@@ -250,10 +251,11 @@ string getURIFromArgs(const std::string& url, const std::string& host, const std
if (host.size() == 0) {
ss << "mongodb://127.0.0.1";
} else {
- if (!str::startsWith(host, "mongodb://")) {
- ss << "mongodb://";
+ if (str::startsWith(host, "mongodb://")) {
+ ss << host;
+ } else {
+ ss << "mongodb://" << uriEncode(host);
}
- ss << host;
}
if (!hostEndsInSock) {
@@ -270,7 +272,7 @@ string getURIFromArgs(const std::string& url, const std::string& host, const std
}
}
- ss << "/" << url;
+ ss << "/" << uriEncode(url);
return ss.str();
}
diff --git a/src/mongo/shell/mongo.js b/src/mongo/shell/mongo.js
index 231206a9766..76d0d53dfb0 100644
--- a/src/mongo/shell/mongo.js
+++ b/src/mongo/shell/mongo.js
@@ -234,6 +234,9 @@ connect = function(url, user, pass) {
if (!url.startsWith("mongodb://")) {
const colon = url.lastIndexOf(":");
const slash = url.lastIndexOf("/");
+ if (url.split("/").length > 1) {
+ url = url.substring(0, slash).replace(/\//g, "%2F") + url.substring(slash);
+ }
if (slash == 0) {
throw Error("Failed to parse mongodb:// URL: " + url);
}