Skip to content

Commit

Permalink
Merge pull request #40 from carlo-colombo/master
Browse files Browse the repository at this point in the history
When url ends with / overwrite dbname with empty string
  • Loading branch information
kcbanner committed Sep 9, 2012
2 parents bfc03e8 + dc4045a commit fa75824
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/connect-mongo.js
Expand Up @@ -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];
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions test/connect-mongo.test.js
Expand Up @@ -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.