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 fc5f32a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/connect-mongo.js
Original file line number Diff line number Diff line change
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
14 changes: 14 additions & 0 deletions test/connect-mongo.test.js
Original file line number Diff line number Diff line change
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 fc5f32a

Please sign in to comment.