From 4e1692b74ff4b64b4f2180efc090d62f672a1751 Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Tue, 28 Sep 2010 21:55:53 -0700 Subject: [PATCH] Fix unix socket parsing and add test SERVER-1867 --- client/dbclient.cpp | 2 +- jstests/unix_socket1.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 jstests/unix_socket1.js diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 0150f0aa71a..3ca0956b51f 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -75,7 +75,7 @@ namespace mongo { ConnectionString ConnectionString::parse( const string& host , string& errmsg ){ string::size_type i = host.find( '/' ); - if ( i != string::npos ){ + if ( i != string::npos && i != 0){ // replica set return ConnectionString( SET , host.substr( i + 1 ) , host.substr( 0 , i ) ); } diff --git a/jstests/unix_socket1.js b/jstests/unix_socket1.js new file mode 100644 index 00000000000..8b5daae32bb --- /dev/null +++ b/jstests/unix_socket1.js @@ -0,0 +1,15 @@ +if ( ! _isWindows() ) { + hoststring = db.getMongo().host + index = hoststring.lastIndexOf(':') + if (index == -1){ + port = '27017' + } else { + port = hoststring.substr(index + 1) + } + + sock = new Mongo('/tmp/mongodb-' + port + '.sock') + sockdb = sock.getDB(db.getName()) + assert( sockdb.runCommand('ping').ok ) +} else { + print("Not testing unix sockets on Windows"); +}