Browse Source

util: make _extend() more robust

Add a better 'is object?' check, the old one let values like true slip through.
v0.9.1-release
Ben Noordhuis 13 years ago
parent
commit
928d28a7b3
  1. 2
      lib/util.js
  2. 9
      test/simple/test-util.js

2
lib/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;

9
test/simple/test-util.js

@ -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});

Loading…
Cancel
Save