Permalink
Browse files

fixed; overwriting of query arguments

closes #1176
  • Loading branch information...
1 parent b271fde commit 168f32e38e4fc67bba6f91fcb21c0e8452a067f0 @aheckmann aheckmann committed Oct 30, 2012
Showing with 32 additions and 1 deletion.
  1. +23 −1 lib/utils.js
  2. +9 −0 test/query.test.js
View
24 lib/utils.js
@@ -378,11 +378,33 @@ exports.merge = function merge (to, from) {
if ('undefined' === typeof to[key]) {
to[key] = from[key];
} else {
- merge(to[key], from[key]);
+ if (exports.isObject(from[key])) {
+ merge(to[key], from[key]);
+ } else {
+ to[key] = from[key];
+ }
}
}
};
+/*!
+ * toString helper
+ */
+
+var toString = Object.prototype.toString;
+
+/**
+ * Determines if `arg` is an object.
+ *
+ * @param {Object|Array|String|Function|RegExp|any} arg
+ * @return {Boolean}
+ */
+
+exports.isObject = function (arg) {
+ return '[object Object]' == toString(arg);
+}
+
+
/**
* A faster Array.prototype.slice.call(arguments) alternative
* @api private
View
9 test/query.test.js
@@ -424,6 +424,15 @@ describe('Query', function(){
assert.ok(!threw);
})
+ it('works with overwriting previous object args (1176)', function(done){
+ var q = new Query();
+ assert.doesNotThrow(function(){
+ q.find({ age: { $lt: 30 }});
+ q.find({ age: 20 }); // overwrite
+ })
+ assert.deepEqual({ age: 20 }, q._conditions)
+ done();
+ })
})
describe('size', function(){

0 comments on commit 168f32e

Please sign in to comment.