Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 928d28a7b326fb8f47ded5257ede7634fe44578b 1 parent 5979f09
Ben Noordhuis bnoordhuis authored
Showing with 10 additions and 1 deletion.
  1. +1 −1  lib/util.js
  2. +9 −0 test/simple/test-util.js
2  lib/util.js
View
@@ -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
View
@@ -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});
Please sign in to comment.
Something went wrong with that request. Please try again.