Skip to content
This repository has been archived by the owner. It is now read-only.
Browse files

util: make _extend() more robust

Add a better 'is object?' check, the old one let values like true slip through.
  • Loading branch information...
bnoordhuis committed May 10, 2012
1 parent 5979f09 commit 928d28a7b326fb8f47ded5257ede7634fe44578b
Showing with 10 additions and 1 deletion.
  1. +1 −1 lib/util.js
  2. +9 −0 test/simple/test-util.js
@@ -509,7 +509,7 @@ exports.inherits = function(ctor, superCtor) {

exports._extend = function(origin, add) {
// Don't do anything if add isn't an object
if (!add) return origin;
if (!add || typeof add !== 'object') return origin;

var keys = Object.keys(add);
var i = keys.length;
@@ -69,3 +69,12 @@ assert.equal(false, util.isError({}));
assert.equal(false, util.isError({ name: 'Error', message: '' }));
assert.equal(false, util.isError([]));
assert.equal(false, util.isError(Object.create(Error.prototype)));

// _extend
assert.deepEqual(util._extend({a:1}), {a:1});
assert.deepEqual(util._extend({a:1}, []), {a:1});
assert.deepEqual(util._extend({a:1}, null), {a:1});
assert.deepEqual(util._extend({a:1}, true), {a:1});
assert.deepEqual(util._extend({a:1}, false), {a:1});
assert.deepEqual(util._extend({a:1}, {b:2}), {a:1, b:2});
assert.deepEqual(util._extend({a:1, b:2}, {b:3}), {a:1, b:3});

0 comments on commit 928d28a

Please sign in to comment.
You can’t perform that action at this time.