Skip to content

Commit

Permalink
Don't modify connection object.
Browse files Browse the repository at this point in the history
Closes #469
  • Loading branch information
dxg committed Mar 13, 2014
1 parent 3d1d026 commit 23abc6b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/ORM.js
Expand Up @@ -65,14 +65,16 @@ exports.connect = function (opts, cb) {
if (arguments.length === 0 || !opts) {
return ORM_Error(new ORMError("CONNECTION_URL_EMPTY", 'PARAM_MISMATCH'), cb);
}
if (typeof opts === "string") {
if (opts.replace(/\s+/, "").length === 0) {
if (typeof opts == 'string') {
if (opts.trim().length === 0) {
return ORM_Error(new ORMError("CONNECTION_URL_EMPTY", 'PARAM_MISMATCH'), cb);
}
opts = url.parse(opts, true);
for(var k in opts.query) {
opts[k] = opts.query[k];
}
} else if (typeof opts == 'object') {
opts = _.cloneDeep(opts);
}
if (!opts.database) {
// if (!opts.pathname) {
Expand Down
20 changes: 20 additions & 0 deletions test/integration/orm-exports.js
@@ -1,3 +1,4 @@
var _ = require('lodash');
var sqlite = require('sqlite3');
var pg = require('pg');
var should = require('should');
Expand Down Expand Up @@ -138,6 +139,25 @@ describe("ORM.connect()", function () {
});
});

it("should not modify connection opts", function (done) {
var opts = {
protocol : 'mysql',
user : 'notauser',
password : "wrong password",
query : { pool: true, debug: true }
};

var expected = JSON.stringify(opts);

ORM.connect(opts, function (err, db) {
should.equal(
JSON.stringify(opts),
expected
);
done();
});
});

it("should emit no error if ok", function (done) {
var db = ORM.connect(common.getConnectionString());

Expand Down

0 comments on commit 23abc6b

Please sign in to comment.