Permalink
Browse files

Merge pull request #40 from carlo-colombo/master

When url ends with / overwrite dbname with empty string
  • Loading branch information...
kcbanner committed Sep 9, 2012
2 parents bfc03e8 + dc4045a commit fa758240e157b1b0355a89c5850fc2ea2bc66b8b
Showing with 17 additions and 3 deletions.
  1. +2 −2 lib/connect-mongo.js
  2. +1 −1 package.json
  3. +14 −0 test/connect-mongo.test.js
View
@@ -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
@@ -5,7 +5,7 @@
"keywords": ["connect", "mongo", "mongodb", "session", "express"],
"author": "Casey Banner <kcbanner@gmail.com>",
"dependencies": {
- "mongodb": "0.9.x"
+ "mongodb": "1.0.x"
},
"devDependencies": {
"mocha": "1.x",
View
@@ -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 fa75824

Please sign in to comment.