Avoid stack overflow with _.defaultsDeep.

This commit is contained in:
John-David Dalton
2015-08-13 01:30:24 -07:00
parent 9f0dd40b3b
commit dd472f489b
2 changed files with 24 additions and 6 deletions

View File

@@ -3023,6 +3023,26 @@
strictEqual(actual.a.b, 2);
});
test('should merge sources containing circular references', 1, function() {
var object = {
'foo': { 'b': { 'c': { 'd': {} } } },
'bar': { 'a': 2 }
};
var source = {
'foo': { 'b': { 'c': { 'd': {} } } },
'bar': {}
};
object.foo.b.c.d = object;
source.foo.b.c.d = source;
source.bar.b = source.foo.b;
var actual = _.defaultsDeep(object, source);
console.log(actual.bar.b === actual.foo.b , actual.foo.b.c.d === actual.foo.b.c.d.foo.b.c.d);
ok(actual.bar.b === source.foo.b && actual.foo.b.c.d === actual.foo.b.c.d.foo.b.c.d);
});
}());
/*--------------------------------------------------------------------------*/