Skip to content

Commit

Permalink
fix(deepMerge): support copying Buffers
Browse files Browse the repository at this point in the history
fixes #268
  • Loading branch information
mbroadst committed Oct 19, 2016
1 parent 00afee0 commit db6295f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,16 @@ function deepMerge() {
s2 = src;
} else {
if (!tgt[key]) {
tgt[key] = new src[key].constructor();
if (src[key] instanceof Buffer) {
tgt[key] = new Buffer(src[key]);
} else {
tgt[key] = new src[key].constructor();
}
}
t2 = tgt[key];
s2 = src[key];
}

for (var k2 in s2) {
if (s2.hasOwnProperty(k2)) {
var v2 = s2[k2];
Expand Down
5 changes: 5 additions & 0 deletions test/unit/test_utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ describe('Utilities', function() {
expect(merged).to.eql({ foo: { bar: 1, baz: 2, zoop: 1 }, bat: 3, dubin: { a: 1 }});
});

it('should work with Buffers', function() {
var merged = u.deepMerge({}, { test: new Buffer([0xDE, 0xAD, 0xBE, 0xEF]) });
expect(merged.test).to.eql(new Buffer([0xDE, 0xAD, 0xBE, 0xEF]));
});

// @todo Fix deepMerge to preserve object __proto__ identity.
// it('should work for nested with custom types', function() {
// var nested = { foo: { bar: new AMQPSymbol('s1') } };
Expand Down

0 comments on commit db6295f

Please sign in to comment.