Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #40 from carlo-colombo/master

When url ends with / overwrite dbname with empty string
  • Loading branch information...
commit fc5f32afcb7c09ad2a570ae35f486dc5db62940c 2 parents bfc03e8 + dc4045a
@kcbanner authored
Showing with 16 additions and 2 deletions.
  1. +2 −2 lib/connect-mongo.js
  2. +14 −0 test/connect-mongo.test.js
View
4 lib/connect-mongo.js
@@ -49,11 +49,11 @@ module.exports = function(connect) {
if (db_url.pathname != undefined) {
var pathname = db_url.pathname.split('/');
- if (pathname.length >= 2) {
+ if (pathname.length >= 2 && pathname[1]) {
options.db = pathname[1];
}
- if (pathname.length >= 3) {
+ if (pathname.length >= 3 && pathname[2]) {
options.collection = pathname[2];
}
}
View
14 test/connect-mongo.test.js
@@ -221,3 +221,17 @@ exports.test_clear_expired = function(done) {
});
};
+exports.test_options_url_and_db = function(done){
+ var store = new MongoStore({
+ url: 'mongodb://test:test@127.0.0.1:27017/',
+ db : 'connect-mongo-test',
+ collection:'sessions-test'
+ }, function() {
+ assert.strictEqual(store.db.databaseName, 'connect-mongo-test');
+ assert.strictEqual(store.db.serverConfig.host, '127.0.0.1');
+ assert.equal(store.db.serverConfig.port, 27017);
+ assert.equal(store.collection.collectionName, 'sessions-test');
+ cleanup_store(store);
+ done();
+ });
+}

0 comments on commit fc5f32a

Please sign in to comment.
Something went wrong with that request. Please try again.